I have my dataset (d.asc) as follows:
0.1 0.5
0.12 0.56
...
90.4 0.34
...
100 0.78
I have my plot generation file as follows:
set xrange [0.1:100]
set grid
plot "d.asc" using 1:2 notitle with lines
I.e. I want to see first column on x-axis, and second column on y-axis. But, the x-axis values start from 0 and increment by 10 upto 100.
[1] Why it does not start from 0.1?
[2] Also is there a way to have only three (or four, etc.) specific value points on x-axis? For example I want to see on x-axis only 0.1, 90.4, and 100. Thanks.
[1] Why it does not start from 0.1?
Gnuplot likes to pick round numbers for its tic increments and positions. In your case the increments are 10, so they would appear at 0, 10, ... 100. Since you manually set the x range to start at 0.1 a tic does not appear until 10.
[2] Also is there a way to have only three (or four, etc.) specific value points on x-axis?
Yes, you can specify specific points with this syntax:
set xtics ("0.1" 0.1, "90.4" 90.4, "100" 100)
The value in quotes is the text that appears at the tic, and the number is the actual position at which it appears. (help set xtics for more format info.)
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 am trying to populate graph with some fixed values on X-axis and corresponding values on Y-axis. With my below script, no values are labelled on X-axis and value on Y-axis are labelled with powers.
How to make xtics data(1000, 10000, 100000, 1000000, 10000000) appear on X-axis ?
How to get rid of powers on Y-axis ? (Example : I want 4000000 on Y-axis instead of 4x10^6
set xrange [0:]
set output "macs.png"
set ylabel "Flows/sec"
set xlabel "MACS per Switch"
set grid
set xtics (1000, 10000, 100000, 1000000, 10000000)
set style line 2 lt 1 lw 2 pt 1 linecolor 1
plot "macs.data" using :1 with linespoints linestyle 0 title "Floodlight" // Using ":1" as X-axis data is supplied in xtics
Here is my data file :
# Not Supplying X-axis data here as it is supplied through xtics
400
60000
700000
800000
900000
I want my populated graph with only one line to looks like this :
You have supply x and y value for each point. Fortunately, gnuplot supports some special column numbers like column 0, which is a counter of valid data sets, i.e. here a line number ignoring comments. It starts at zero.
Next, your x-axis uses a log scale, so you should do it, too. The formula to convert line number to correct x-value is 10(colum_0) + 3. which translates to 10**($0+3) in gnuplot.
Here is the code:
# Logarithmic scale for x axis
set log x
# get rid of scientific formatting of numbers,
# plain format also for large numbers
set format x "%.0f"
# If you don't like the small ticks between the large ones
set mxtics 1
# put the key (legend) outside, right of the plot area,
# vertically centered (as in your picture)
set key outside right center
# only horizontal grid lines
set grid y
plot "macs.data" using (10**($0+3)):1 title "foo" with linespoints
And here the result:
Alternative:
Your approach plots the data as if it were given like
0 400
1 60000
2 700000
3 800000
4 900000
In this case, you need to label the x-axis on your own, the correct syntax is
set xtics("1000" 0, "10000" 1, "100000" 2, "1000000" 3, "10000000" 4)
This will not draw any automatic labels, but it will put e.g. your string 10000 at x=1
I have a dataset
200 45000
600 260000
2000 680000
18000 2800000
I generated this by processing other data (set like {(x0, y0), (x1, y1),..}). On the first row in the first column is the low quartile of x and in the second column is sum of ys corresponding to data with x_0 < 200. In the second column it is similar but the first column is median and second column is the mentioned sum for 200 < x_0 <= 600. Third is similar (just with high quartile), fourth has the maximum value of x in the first column.
I want to render a box plot similar to the one below but the xtics should be right between the borders of the boxes (so each box would be between two xtics). How can I do that? The manual page for "set xtics" didn't help.
This was generated by this code (few unimportant style settings not shown):
plot 'data/example.dat' using 1:2:xtic(1) with boxes
There is a related question Gnuplot put xtics between bars but I don't think I can apply that since I want my boxes to keep their width (although I need to somehow modify it a bit so that 200 and 600 don't overlap).
You can use the fsteps plotting style. But, with this you need to add an additional line to get the plot right:
0 45000
200 45000
600 260000
2000 680000
18000 2800000
and plot this e.g. with
set xtic rotate
plot 'test.dat' using 1:2:xtic(1) with fsteps lw 3 notitle
I want gnuplot to plot an irregular timeseries as bars, but my bars are always placed at day boundaries (the midnight marks), as if the time info were ignored (e.g. the first two entries show up on top of each other at midnight). The days are spaced widely enough, it's not an issue of the bars being too scrunched up. Sample data:
07/09/2012-00:00 1 741 0.50
07/09/2012-12:00 2 3087 0.50
07/12/2012-00:00 1 2011 0.33
07/12/2012-08:00 2 814 0.33
07/12/2012-16:00 2 99 0.33
The relevant gnuplot code below. The xtics settings are just for aesthetics, they have no bearing on the issue.
set xdata time
set timefmt "%m/%d/%y-%H:%M"
set xtics format "%m/%d"
set xtics "07/08/2012-00:00", 2*172800 ,"08/28/2012-00:00"
plot FILE using 1:3:2 with boxes lc variable
Two separate, but related questions: 1) Can I remove the leading zeros from x-axis labels (i.e 7/8, not 07/08) to save space ("%m" and "%d" always give me leading zeros)? 2) Can I vary the width of a bar based on data from file (in this case, I'd like the 4th column to be a fractional multiplier for the standard bar width)? Thanks.
Your time format is wrong. you want %Y (4-digit year) instead of %y (2-digit year).
In order to specify the width, you'll need 4 columns of data:
plot FILE using x_column:y_column:x_width:linestyle w boxes lc variable
where x_width is the width of the box in seconds (since that is the unit on a time-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