Staggered bar chart in gnupplot - gnuplot

There is a great question about bar charts in gnuplot.
How do you plot bar charts in gnuplot?
What is missing (and what I'm asking about) is a staggered bar chart.
The example in the other question giving the bars side-by-side. The staggered bars there are additive. I want to have the bar in front of (or superimposed of) each other.
Let's say I have data:
10 20
30 50
60 80
10 50
0 20
I want 5 vertical bars.
The first one bottom 10 units are red, the next 10 units are blue. The next bar to The right has 30 units red on bottom and 20 units blue on top. Etc.
Thanks,
Gert

Does this do what you want (I wasn't sure I understood what you were aiming for)?:
set style data histogram
set style fill solid border -1
plot 'gert' u 1 lc 'red', '' u ($2 - $1) lc 'blue'

Related

gnuplot: label overflowing outside canvas isn't drawn

I'm putting labels on top (offset by 10) of histogram bars like this:
plot "hist.txt" using 1:2 with boxes ls 1, "hist.txt" using 1:($2+10):(sprintf("%.1f%%",$2)) with labels
When the bar value is 87%, it draws the label.
When the bar value is 92%, the label isn't drawn, probably since there isn't enough space left. How do I tell it to draw the label anyway, and I don't mind if it would overflow the intended canvas size?
Assuming you limit the range of the y-axis to 0~100, the y-value of 92 + 10(= 102) will not be drawn because it exceeds the maximum value of yrange.
It works well if you use with labels offset 0, first 10 as the plot style specification instead of shifting the position of the label in using.
set key noautotitle
set tmargin screen 0.85
set xrange [0:11]
set yrange [0:100]
plot "hist.txt" using 1:2 with boxes ls 1, \
"hist.txt" using 1:2:(sprintf("%.1f%%",$2)) with labels offset 0,first 10
Sample "hist.txt" is,
1 30
2 60
3 87
4 92
5 50
6 20
7 10
8 30
9 50
10 40

How to create an overlapping bar chart in gnuplot

I looked for an answer to this question but wasn't able to find one that exactly matched with my particular problem.
First of all, I am using gnuplot (since I haven't found this answer also using Julia...)
The issue:
I have a file (test.dat) which is basically an array. It has 100 rows and 50 columns. Each row represents a bar chart that I need to plot. IN each column of that row, there is the value or magnitude of the bar. Simple.
So I need to plot all rows (a total of 100 bar charts) in the same graph. Also, I need it to be with transparency, so I can see all the bar-charts.
Can anybody help me with this problem?
You use this to set transparency:
set style fill transparent solid 0.5
0.5 is the level of transparency.
But if I understood the question correctly, your data format may be problematic. With the following data:
1 10 50
2 20 40
3 30 30
4 40 20
5 50 10
so 2 charts, each with 5 elements, and the following gnuplot instructions:
set terminal pngcairo truecolor size 800, 600
set output "data.png"
set style fill transparent solid 0.5
set style data boxes
set boxwidth 0.5
plot 'data.txt' using 1:2 title 'foo' linetype rgb 'red', \
'' using 1:3 title 'bar' linetype rgb 'web-blue'
you will get this:

Gnuplot Histogram with overlapping bar pairs

I am trying to plot a bar chart/histogram that shows, for every point of the x axis, two bars, each of which is divided in three parts. Take the following dataset:
Min # Max # Avg # Min % Max % Avg %
6 12 6.67 13 100 35.25
0 6 3 0 90 43.25
235 1243 553 66.67 100 83.43
The idea is that for each row, there will be a pair of vertical bars, with the left one representing the three # values and the right one representing the three % values. The values are made-up, but the scale is more or less the real one.
So far, I have managed to get the following script, which is a frankenstein of several online scripts I found:
set ytics 10 nomirror tc lt 1
set y2tics 100 nomirror tc lt 2
set yrange [0:120]
set y2range [0:1500]
set style fill solid border -1
plot "table2.dat" using 5:xticlabels(1) with boxes lt rgb "#40FF00" t "Max \%",\
"" using 6 lt rgb "#406090" t "Avg \%",\
"" using 4 with boxes lt rgb "#403090" t "Min \%"
This will plot out the following chart:
What I cannot seem to figure out is how to put the second bar for the first three columns. Ideally, that "X" would also be replaced by a dotted line cutting the bar. The reason for the two Y axes is that each bar follows a different scale, so the second bar would have to be proportional to the right-side y axis. Finally, I had to add that little "hack" of making yrange higher than 100 so that the bars would not "hit the top". If there is another way to do that, that'd be great.
Thanks in advance for any help that can be given, I am a complete newbie at gnuplot but since trying to make this chart using spreadsheet tools was an even bigger pain, I am hopeful that someone'll be able to help with at least some of those problems.
Edit.: I will take suggestions for a better title for this question.
You can get a little further by setting a boxwidth to 0.4 of the default width, and defining a function (I used f here) that converts your data in columns 1 to 3 into percentage values too, and explicitly providing an x coordinate with the syntax x:y and using $1 to refer to column 1 etc. $0 is the row.
set boxwidth 0.4 relative
f(y,max) = (y*100./max)
plot "table2.dat" \
using 5:xticlabels(1) with boxes lt rgb "#40FF00" t "Max \%",\
"" using 6 lt rgb "#406090" t "Avg \%",\
"" using 4 with boxes lt rgb "#403090" t "Min \%",\
"" using ($0-.5):(f($2,$2)) with boxes lt rgb "red" t "Max",\
"" using ($0-.5):(f($3,$2)) lt rgb "blue" t "Avg",\
"" using ($0-.5):(f($1,$2)) with boxes lt rgb "orange" t "Min"
I used some garish colours to show the new boxes:

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 boxes with different color bars

I want to plot a histogram like chart with boxes. And I hope the bars have different colors. I found some previous cases, use lc rgb variable, but it doesn't work for me. My version is limited to gnuplot4.2. Here is my data sheet:
stage 11402.364 100% 1
App1 78.552 0.69% 2
App2 11323.812 99.30% 2
Read 8.469 0.07% 3
Write 41.285 0.04% 3
Repeat 5748.351 50.41% 3
Count 4933.746 43.27% 3
Count_1 3841.355 33.69% 4
Count_2 1092.391 9.59% 4
Here is the code part:
set boxwidth 0.5 relative
set style fill solid 0.5
set xtics rotate
plot 'histogramdata_2.txt' using 2:xtic(1):4 with boxes variable lc rgb variable notitle
I want to use the 4th column to denote the bar color. The document said the third number used in using is just the color variable. But it doesn't work for me, the result is no bar produced.
It seems that the using part is quite flexible. I even find some cases in this site put 4 column numbers after using.
It is related to different versions?
Your plot command seems to be wrong. Try the following:
set boxwidth 0.5 relative
set style fill solid 0.5
set xtics rotate
plot 'histogramdata_2.txt' using 0:2:4:xticlabels(1) with boxes lc variable
It should look like this:
In short about the using 0:2:4:xticlabels(1) part:
0 tells gnuplot to place bars (x value) in the same order as they appear on the file
2 tells gnuplot to take y values from column 2
4 tells gnuplot to take the color variable from the 4th column
xticlabels(1) tells gnuplot to take the text labels for the bars from column 1

Resources