Display power of 10 at axis' end - gnuplot

My data runs from 0 to 800000 on the x-axis and I have 4 plots in a square. To make the scale readable, I'd like to label the ticks from 0 to 8 (i.e. with %1.0t) and write the *10^5 at the end of the scale. I tried several format options, but all of them add *10^5 or e5 behind each tick. Is there a way to only put it in the end instead of each one?

set xtics 100000 format "%1.0t"
set label "*10^5" at graph 1, 0 offset 4
However the more conventional approach is to explain the scale in the axis label:
set xlabel "Whatever it is (x 10^5)"

Related

Is there a way to change the y axis on Gnuplot so that my image graphs from hour 16 to hour 15 instead of 0 to 24?

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

gnuplot: xtics not shown on X-axis

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

Position xtics between bars

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

gnuplot how to set tics format by power of 10

I have a plot with:
xtics = {0, 2000, 4000, ..., 20000}
and I would like them to be shown as:
0 2 4 ... 20
x 10^3
Is there any way to do so?
You can do so by setting a label at the appropriate position:
set label 1 "× 10³" right at graph 1, -0.05
This would place the text × 10³ right aligned with the right border of your plot and somewhat below it. You probably have to adjust the vertical position (−0.05) a bit depending on your plot.
However, I recommend against indicating factors like that and suggest to incorporate them in the axis label and use set xlabel "amount [10³ potatoes]" for example. The kind of labels you want to use are easy to miss and fortunately not common anymore.

How to set axis units in gnuplot

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)

Resources