1

I am using gracebat of xmgrace to generate bar graphs using the following batch script.

s0 line type 0
S0 SYMBOL COLOR 4
S0 SYMBOL FILL 1
s0 type BAR
## Bar fill. Only 1 (black) is available.
 S0 FILL WITH COLOR
 S0 FILL COLOR 3
## Outline width.
S0 SYMBOL LINEWIDTH 2
# options for image output
WORLD XMIN 0
WORLD YMIN 0
PAGE SIZE 800, 600

The first issue that sometimes the script automatically sets the 0.5 spacing on X, while I need always 1. Here is the example:

enter image description here

How I could eliminate those unused 0.5 spacings via some option in my batch file?

The second problem (again on X axis): sometimes the graph cover wider range of values on 2 without any of data:

enter image description here

Is it possible to automatically limit XMAX according to the initial dataset (but without its seting manualy in batch script since I apply it to different xvg files)?

Quasímodo
  • 18,625
  • 3
  • 35
  • 72
user3470313
  • 203
  • 1
  • 5

1 Answers1

1

How I could eliminate those unused 0.5 spacings via some option in my batch file?

With XAXIS TICK MAJOR 1.

Is it possible to automatically limit XMAX according to the initial dataset?

The documentation says

graphno AUTOSCALE TYPE SPEC
Set the method of autoscaling to use the minimum and maximum values of the data.

So one could think G0 AUTOSCALE TYPE SPEC would do it, nevertheless it does not, at least not in the stable version of Xmgrace.

An alternative is to extract the maximum values of the X and Y axis from the data file with a program (say, awk), and use that to generate the appropriate batch commands. Say, save this as batchplot:

awk '
  NR==1{
    max1=$1
    max2=$2
  }
  $1>max1{max1=$1}
  $2>max2{max2=$2}
  END{printf "WORLD XMAX %s\nWORLD YMAX %s\n",max1,max2 >> "a.xmg"}
' a.dat
xmgrace -nosafe -batch a.xmg a.dat

Make it executable with chmod +x batchplot, substitute a.xmg and a.dat by the name of the batch and data file, and then just run it. It will append the X and Y axes limits to the batch and then run it.

Advice: If you are planning to use more complicated plotting features, the command-line interface of Xmgrace will prove to be a pain. This and your other question already indicate so. In that case, I recommend GNUPlot or Matplotlib, which were born to be scriptable.

Quasímodo
  • 18,625
  • 3
  • 35
  • 72
  • thank you very much for your suggestions! Yes, it would be interesting to look on AWK expression (if it is not something very complicated, that I could use for pre-processing of XVG filles). I suppose I need some AWK script, which would scan XVG file and capture its Xmax (I don't care about Ymax presently) in a distinct variable, that I will use in my batch script as XMAX, isn't it? if it is nessesary I can add example of XVG to my first post... – user3470313 Oct 27 '20 at 13:12
  • @user3470313 I have added how you would go about that in Awk. Yes, it captures the maximum X and Y in max1 and max2 variables and then appends the batch statement to the batch file. – Quasímodo Oct 27 '20 at 13:24
  • yes! I've adapted your AWK sollution with my bash script and it works fine and do fantastical job. Thank you again! One question: is there some option for batch file to demonstrate always XMAX and YMAX on the corresponded AXES ? sometimes this marker is missed on graph ( I attach a picture to my first post) – user3470313 Oct 27 '20 at 16:10
  • @user3470313 You are welcome. That happens whenever the major ticks interval is not a multiple of the minor ticks interval, so there is nothing you can do, sorry. – Quasímodo Oct 27 '20 at 20:13
  • hello, I've just fixed it via addition of +1 to xmax and xmin in your AWK script in order that the both axes always have 1 additional point in both directions .. :-) END{printf "WORLD XMAX %s\nWORLD YMAX %s\n",max1+1,max2+1 sorry I don't know a proper syntax of AWK but functionally it works well – user3470313 Oct 28 '20 at 08:37
  • @user3470313 Alright, I thought you meant you wanted the last tick of the axis to always appear, which only happens in the case I meantion in the previous comment. – Quasímodo Oct 28 '20 at 10:56