Position xtics between bars - gnuplot

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

Related

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

Gnuplot - How to place y-values above bars when using Histogram style?

I am currently using a script to generate histogram plots, e.g., by doing:
set style histogram cluster gap 4
plot for [COL=2:10] 'example.dat' u COL:xticlabels(1) title columnheader(COL)
Now I wish to add the y-values (numbers) above the bars in the histogram but adding w labels gives the 'Not enough columns for this style' error.
plot for [COL=2:10] 'example.dat' u COL:xticlabels(1) title columnheader(COL), \
for [COL=2:10] 'example.dat' u COL title '' w labels
Is it possible to add y-labels using the histogram style?
Note: I know that there are examples for plotting with boxes. I wish to make this work with the histogram style if possible.
Here's a test datafile I came up with:
example.dat
hi world foo bar baz qux
1 2 3 4 5 6
4 5 7 3 6 5
Here's the script I used to plot it:
set yrange [0:*]
GAPSIZE=4
set style histogram cluster gap 4
STARTCOL=2 #Start plotting data in this column (2 for your example)
ENDCOL=6 #Last column of data to plot (10 for your example)
NCOL=ENDCOL-STARTCOL+1 #Number of columns we're plotting
BOXWIDTH=1./(GAPSIZE+NCOL) #Width of each box.
plot for [COL=STARTCOL:ENDCOL] 'example.dat' u COL:xtic(1) w histogram title columnheader(COL), \
for [COL=STARTCOL:ENDCOL] 'example.dat' u (column(0)-1+BOXWIDTH*(COL-STARTCOL+GAPSIZE/2+1)-0.5):COL:COL notitle w labels
Each cluster of histograms takes a total width of 1 unit on the x axis. We know how many widths we need (the number of boxes +4 since that is the gapsize). We can calculate the width of each box (1/(N+4)). We then plot the histograms as normal. (Note that I added with histogram to the plot command).
According to the builtin help, labels require 3 columns of data (x y label). In this case, the y position and the label are the same and can be read directly from the column COL. The x position of the first block is centered 0 (and has a total width of 1). So, the first block is going to be located at x=-0.5+2*BOXWIDTH. The 2 here is because the gap is 4 boxwidths -- two on the left and 2 on the right. The next block is going to be located at -0.5+3*BOXWIDTH, etc. In general, (as a function of COL) we can write this as
-0.5+BOXSIZE*(COL-STARTCOL+1+GAPSIZE/2)
We need to shift this to the right by 1 unit for each additional block we read. Since each block corresponds to 1 line in the data file, we can use pseudo-column 0 (i.e. column(0) or $0) for this since it gets incremented for each "record/line" gnuplot reads. The 0th record holds the titles, the first record holds the first block. Since we want a function which returns 0 for the first record, we use column(0)-1. Putting it all together, we find that the x-position is:
(column(0)-1-0.5+BOXSIZE*(COL-STARTCOL+1+GAPSIZE/2))
which is equivalent to what I have above.

GNU plot on non uniform data in x axis with fix interval

9 1782.091513,
24 4731.999530,
36 6377.046661,
80 9377.983901,
108 9158.024005,
210 4314.926970,
540 56799.564,
2000 67908.2343,
7000 45345.657,
12000 34234.3624,
Plotting this giving me a graph on which i am not able to see the small values. I want to fix the interval b/w each value of x axis. So that graph will be visible on full table.
You can set your axes to be logarithmic:
set logscale x
set logscale y
Logscale is probably what you actually want here as pointed out by choroba. A second (less standard) way to plot this is to use the values in the first column as the xticlabels.
plot 'yourdatafile' u 2:xticlabels(1)
This will result in a plot where the values are equally spaced on the x-axis, labelled with the corresponding x positions from the datafile.

gnuplot: need help plotting both column and row stacks

I have a datafile listing bandwidth for each machine on a network, but down and up. It looks like:
"" 0 1 2 3
"Machine 1 D" 320 768 1287 1318
"Machine 1 U" 119 245 561 491
Where the first column is the data key, and there's 24 columns representing hours of data. I'd like to generate two histograms,(A) a rowstack that shows the total bandwidth of all the machines for each hour, and (B) a columnstack that shows each machine's hourly usage. So, in graph A, the hours would appear on the x axis, and each machine's usage would stack up cumulatively. In graph B, the machine names would appear on the x axis, and the usage during each hour would stack up cumulatively.
And, for extra credit, I'd like to graph the data twice, alternating rows (once for upload, once down). The trick here, is to preserve the first row as it contains column titles.
Does anyone know how to do this? I can get some results, but can't seem to get the key/xtics/titles etc to show correctly.
EDIT: Ok, so here's an example of what I have for a columnstack -
reset
set style fill solid noborder
file = '..\test\example.dat'
col = 24
set style data histogram
set style histogram columnstacked
plot \
for [i=2:col+1] \
file \
u i title columnhead
Which generates something like:
So, for example, how do I create a key with the column(1) fields?
In the end, I discovered a number of things. First, using iteration in gnuplot seems rather buggy - it works, but constrains other options. Second, I reported a bug where the "every" statement is incompatible with using columnheaders. Third, I can't column/rowstack and declare the x axis as a time/date value. That left me basically writing out the plot long-hand.
columnstacked:
set xtics ("midnight" 0, "1a" 1, ...)
plot file u 3:key(1) notitle, '' u 4, ...
rowstacked:
plot file u 3:xtic(1) t "midnight", u 4 t "1a", ...

Y-value on bar graph in gnuplot?

Can I get gnuplot to display the exact y-value or height of a data point (plotted using "with boxes") over its bar? I would like the plot to be easy to read so nobody has to line up the top of a bar with the y-axis and guess what the value is.
You can use the labels style and combine it into the plot command with the boxes style. The labels style expects 3 columns of data - the x coordinate, the y coordinate, and the actual label text.
For example, with the following data
1 4
2 6
3 2
4 8
the command (we set the yrange to 0 - 10 and boxwidth to 0.9 and set a solid fill style)
plot datafile u 1:2 with boxes, "" u 1:2:2 with labels offset char 0,1
produces
Normally, the labels would be centered on the specified point (the top edge of the box). By specifying an offset, we can move them up to just above the box. Here we used no offset in the x direction, but a unit of 1 in the y direction. We used the character coordinate system, so this corresponds to moving up by one character unit.
I can only think of putting the values where you want them "manually" like this:
set label "value" at 12,34
The numbers are coordinates according to your x and y ranges.
An automatic way would use "with labels", see e.g.
http://gnuplot.sourceforge.net/demo_4.4/stringvar.html

Resources