3

I have a text file (say, sample1.dat) with two columns:first column is a serial no running from 1 to 5000 and second column consists of 5000 dihedral angles varying in between -180 to 180 in degree. By using the command

xmgrace sample1.dat

I got a plot of dihedral angle vs.serial no.

To get the histogram from the plot, I did the following in the pop up window of Grace: Data -> Trasnformation -> Histograms

In the newly pop up window called Grace: Histograms, I selected the source graph but did not select any in the destination graph as explained somewhere in grace tutorials. After selecting start as -180, stop as 180 and number of bins as 5 and then hitting the Accept command in that window, I got the following error message:

[Error] Please select single source and destination graphs

Help me to get the histogram from the plot. I want to use xmgrace to plot the histogram. I know how to plot it using some widely used plotting tools like gnuplot and others.

h k
  • 320
  • 2
  • 13
Mahendra Thapa
  • 163
  • 2
  • 4
  • 12

1 Answers1

8

You nearly had it! Here is a full step-by-step solution: Save the data in a two-column file "sample.dat". Here are the contents of such a file:

#n  angle
1   13
2   -162
3   -63
4   53
5   -170
6   80
7   173
8   39
9   113
[ etc ...] 

In my example file I have 40 entries with randomly-generated angles. Call xmgrace from the command line and load the data file:

xmgrace sample.dat

At first you will see a line plot of angle vs n. We can bin the data and plot a histogram as follows:

Data > Transformations > Histograms

This will open a new window titled "Grace: Histograms". Right-click on your data set "G0.S0" and duplicate it. On the left-hand panel select the original data set by left clicking once. On the right-hand panel select the new data set "G0.S1".

Now at the bottom of the window choose your binning parameters.

Start at: -180

Stop at: 180 

# of bins: 5. 

Click Apply. The histogram is now plotted but the original line plot needs to be hidden. In the left-hand panel right-click on the original data set "G0.S0" and choose "hide".

After all of these steps the "Histograms" window should now look like this:

Grace Histograms window

Finally, in the main xmgrace window, rescale the plot. You should now see the histogram, with your angles binned into five bins. The angle ranges are shown on the x axis and the frequency of each bin range on the y axis. Here is the default output where I have labelled the axes:

output image

The total of the frequencies from all bins should add up to the number of data lines in sample.dat.

feedMe
  • 3,431
  • 2
  • 36
  • 61
  • Is it also possible to calculate the mean value from such a histogram? – thyme Apr 13 '17 at 11:41
  • 1
    Not sure what you mean by 'mean value from a histogram', but mean value of the source data can be calculated using `Data->Feature Extraction` and selecting the `Feature` `Y average`. Of course, this does not use the histogram. – h k Aug 02 '18 at 17:46
  • Just wanted to point out that you don't need the first column. The data file can also be a one-column file, xmgrace will interpret it as the first column was implicitly 1,2,3,4... – valerio Oct 12 '20 at 12:02
  • @feedMe Is it possible to do all these steps on the command line ? – SOUser Jun 07 '21 at 11:40