I'm trying to generate some schematic figures using gnuplot. My x scale is of angstrom and the y scale if of mV. Currently, I have the x scale goes like:
0 1e-9 2e-9 3e-9 etc.
And my y scale goes like
-0.07 -0.06 -0.05 etc.
And I want them to be
0 10 20 30 etc.
-70.0 -60.0 -50.0 etc.
respectively.
Is there a way to do this from within the gnuplot (apart from setting the xrange an yrange parameters and multiplying the values by the appropriate amounts)?
There are two ways that I can think of:
You could make use of set xtics (see documentation here)
Then you can explicitly specify what value on your axis will receive which label. So something like this:
set xtics ("0" 0, "10" 1e-9, "20" 2e-9, ...)
should work. Proceed accordingly with the y axis (set ytics)
You could multiply your values accordingly. (Like what you have mentioned in your question)
plot "Data.dat" u ($1*1e9):($2*1e2)
Related
I'm sorry if this has already been asked, I couldn't find it anywhere, but I have an image plot on gnuplot of a three-columned data file for a y range [0:24] and I can't figure out how to use gnuplot to rearrange the image graph so my y axis runs from 16:24 and then 0:16 (in that order and on the same axis). The command I've been using is "plot [] [0:24] '/Users/eleanor/PycharmProjects/attempt2.gray' u 1:2:3 w image" but I don't know what command to use so that hour 16 is at the very bottom instead of 0, and then when y reaches 23:59 y goes to 0 next and then continues increasing up to 15:59 at the very top of the axis. I'm not sure if that makes sense or not, and I've already tried changing the y range to [16:15] and that did nothing except give me an error lol. Any tips would be very much appreciated! :)
a piece of the file im using is below (with the first column being the day of year, the second being the time in decimal hours, and the third being the data):
20 0.0 7.327484247409568
20 0.002777777777777778 8.304658863945411
20 0.005555555555555556 11.641408500506405
20 0.008333333333333333 6.543382279013497
20 0.011111111111111112 13.922090817182697
20 0.013888888888888888 10.696406455987988
20 0.016666666666666666 12.537636516165243
20 0.019444444444444445 11.816216763447612
20 0.022222222222222223 8.914413125514413
20 0.025 5.8225423124691496
20 0.027777777777777776 10.896730484548698
20 0.030555555555555555 9.097140108173859
As currently implemented, with image treats the entire block of data as a single entity. You can't chop it up into pieces within a single plot command. However if your data is dense enough, it may be that you can approximate the same effect by plotting each pixel as a colored square:
set xrange [*:*] noextend
set yrange [0:24]
plot 'datafile' using 1:(($2>16.)? ($2-16.) : ($2+8.)):3 with points pt 5 lc palette
I strongly recommend not making the range limits part of the plot command. Set them beforehand using set xrange and set yrange.
If necessary, you can adjust the size of the individual square "pixels" by using set pointsize P where P is a scale factor. It probably looks best if you make the points just large enough (or small enough) to touch each other. I think the default ones in the image I show are too large.
You can also use the boxxyerror plotting style instead of the image plotting style. Well, here's what the help for boxxyerror says
gnuplot> ? boxxyerror
The `boxxyerror` plot style is only relevant to 2D data plotting.
It is similar to the `xyerrorbars` style except that it draws rectangular areas
rather than crosses. It uses either 4 or 6 basic columns of input data.
Additional input columns may be used to provide information such as
variable line or fill color (see `rgbcolor variable`).
4 columns: x y xdelta ydelta
6 columns: x y xlow xhigh ylow yhigh
....
If you adopt the four-column plotting style above, you must specify xdelta and ydelta in addition to x and y to specify the rectangle. The xdelta and ydelta should be the half-width and half-height of each pixel. From your data, let's say xdelta is half of 1 and ydelta is half of 0.002777777777777778 hours.
Our final script will look like this.
In this script, the second column of "using" is the same as Ethan's answer.
dx = 1.0/2.0
dy = 0.002777777777777778/2.0
set xrange [-1:32]
set yrange [0:24]
set ytics ("16" 0, "20" 4, "0" 8, "4" 12, "8" 16, "12" 20, "16" 24)
set palette defined (0 "green", 0.5 "yellow", 1 "red")
unset key
plot "datafile" using 1:($2>16?($2-16):($2+8)):(dx):(dy):3 \
with boxxy palette
I'm using gnuplot in a bash script to draw several things.
For this special graphic, I need to print the amount of matrices (y axis) with the matrix size as the x-axis.
As the distribution can be pretty sparsed, I want to use a logscale for x and y. It works great with y, but gnuplot tells me I can't have a logscale for the x-axis when I'm using histogram style.
Any ideas to debug this? or on how to present the results using a similar way?
set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set logscale xy
plot '$res/histo-$ld-$lr-$e-$r' using 2:xtic(1) title 'Run'
The error is :
line 0: Log scale on X is incompatible with histogram plots
Thanks in advance.
Edit : btw, I was using gnuplot 4.4 patchlevel 4 and just updated to the newest version (i.e. 4.6 patchlevel 5)
Gnuplot histograms work a bit differently from what you might think. The x-axis isn't numeric. In your case the value in the first row, second column is placed at an x-value of 0 with the y-value taken from the second column and a manual label taken from the first column, first row. The values of the second row are placed at x=1 etc.
You can try using the boxes plotting style, which is used with a 'conventional' x-axis and supports a logscale in x:
set logscale xy
set offset 0,0,1,1
set boxwidth 0.9 relative
set style fill solid noborder
plot 'data.dat' with boxes
With the data file data.dat
1 1000
2 300
5 150
20 10
135 3
this gives the result (with 4.6.5):
In order to have a fixed boxwidth and a varying box distance, you can use a third column to specify a box width as percentage of the x-value:
set logscale xy
set offset 0,0,1,1
set style fill solid noborder
plot 'data.dat' using 1:2:($1*0.5) with boxes
Putting the actual values on the x-axis works as follows:
set logscale xy
set offset 0,0,1,1
set style fill solid noborder
plot 'data.dat' using 1:2:($1*0.5):xtic(1) with boxes
The figure has too many xtics and ytics. Can I have half of them?
I know I can manually set tics in a way similar to this:
set xtics (1,2,4,8,16,32,64,128,256,512,1024)
But I feel it is not a general solution. You can not manually set tics for all figures. I have loads of them and the gnuplot code is automatically generated using Java.
Here is the code for the figure: https://dl.dropboxusercontent.com/u/45318932/gnuplot2.plt
Can you help lower down the number of x and y tics?
There is no option in gnuplot to explicitly set the number of tics you want on an axis and have gnuplot decide where to put them. (I really wish there were.)
One option you have is to use the stats command (in gnuplot 4.6+) to find out the range of the data:
ntics = 4
stats 'data.dat' using 1 name 'x' nooutput
stats 'data.dat' using 2 name 'y' nooutput
stats 'data.dat' using 3 name 'z' nooutput
set xtics x_max/ntics
set ytics y_max/ntics
set ztics z_max/ntics
You might have to adjust whether you want the tics to be at integer values or not, but that is the general idea.
There are different ways to set the number of tics depending on what exactly you want to do. For a fixed segment of length 2, starting at zero and ending at 32:
set xrange [0:32]
set xtics 0,2,32
plot sin(x)
If you want an exponential increment, try the following
set xrange [0:32]
set for [i=0:5] xtics (0,2**i)
plot sin(x)
Or you can use a logarithmic scale (in base 2 in this case):
set xrange [1:32]
set logscale x 2
plot sin(x)
You can just use for example
set xtic 10
and it will display the tics on x-axis each 10.
I had a similar problem that I wanted to handle a little more generically in case the data changes while still using somewhat round looking numbers. Therefore I made a helper function:
endsinone(n) = strstrt(gprintf("%g", incrguess), "1")
getincr(range, maxincr, guess) = range/guess < maxincr ? guess : \
(endsinone(guess) ? getincr(range, maxincr, 5*guess) : getincr(range, maxincr, 2*guess))
Then I just have to pass in the range for the axis, the most increments I want on it, and a very lower bound guess about what I would expect the smallest possible increment to be. To keep the rounded looking numbers my functions assume the guess is expressible in the form 1eN or 5eN for some value N. Ie (50 is good, so is 0.0000001, 505 is not). With this function you just have to do something like
set xtics getincr(STATS_max, 6, 1e-9)
will return an incr of less than 6 tics, and there should be several of them assuming STATS_MAX > 1e-9.
I have a data row with lots of dots, plotted as markers. X-axis values range between 0 and 80 ms, and Y-values take discrete values of 1,2,..5. There are about 50000 points, so if I just plot them as usual, the Y-value changing dynamics is not clear, as you see for example a solid line forming at Y value 5, with a few dropouts at 3 and 4. I would like to modify my plot to zoom in the first millisecond - the half of the X-axis should be occupied by the range 0-1ms, and the rest 1-80ms. Any idea how to achieve this?
Use this:
set yrange [-1:1.3]
set xrange [0:12]
set x2range [40:150]
set xtics 0,1,5
set x2tics 100,10,150 mirror offset 0,-21.6
plot (x<5?sin(x):0/0) axis x1y1 tit "f(x)", (x>100?cos(x):0/0) axis x2y1 tit "g(x)"
Constant -21.6 is setting up xtics labels for second part but according to x2 (upper) axis... So you must fit this constant according to graph height and used terminal. Also you have to change range and tics settings to obtain continuous x axis.
I am trying to create a barchart using gnuplot. My requirement is that I should be able to label y-axis as 0, 1, 100, 10,000 (i.e., each tick increases by a factor of 100, except between 1 and 0). Also, this is not log-scale as I want this to start at 0. Let me know if you know how to do this.
You can use set xtics:
gnuplot> set xtics ("0" 1, "1" 2, "100" 3, "10000" 4)
gnuplot> plot "test.dat" notitle with boxes
produces the following plot:
http://marco.uctleg.net/resources/sample_xtics.png
with the following data:
1 12
2 8
3 19
4 42
EDIT: Just noticed you asked to change the y-axis. It's much the same, I'm sure you can work it out.
Marcog's answer is probably the best way to get exactly what you want,
However, if you don't want to do the reassignment of 1 means "0", 2 means "1" etc,
then you could try a simple
set ytics (0,1,100,10000)
To set the tics where you want them,
and then use the set format y to specify the format of the tics.
For example
set format y "10^{%L}"
to put the tics in nice exponential form (note this particular formatting looks pretty in postscript output, but rather ugly in the default gnuplot window).
See http://t16web.lanl.gov/Kawano/gnuplot/tics-e.html for more on the set format command (midway down the page).
All the best