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:
Related
I would like to create a histogram with boxes using three pieces of data, first the number of iterations as the x-axis, then the execution time as the y-axis and finally the number of processes used.
I would like to see a bar for each number of processes used, and with a color specific to the value of the number of processes. How can I do this?
My test data is defined as:
"iterations" "processes" "time_execution"
1000 1 14
1000 2 10
1000 4 9
4000 1 60
4000 2 42
4000 4 45
7000 1 80
7000 2 70
7000 4 50
And here is my script so far, but I can't get it to place the three bars side by side:
set term svg
set output out.svg
set boxwidth 1
set style fill solid 1.00 border 0
set style histogram
set size ratio 0.8
set xlabel 'Number of iterations'
set ylabel offset 2 'Time execution in seconds'
set key left Right
set key samplen 2 spacing .8 height 3 font ',10'
set title 'Time execution per iterations and processus used'
plot test.data u 1:3:2 w boxes
Thanks!
I guess your data format doesn't fit the expected histogram format. Check the examples on the gnuplot homepage, although, I think the examples are too crowded which might be confusing and maybe the reason why there are so many histogram questions on SO.
If you modify your data format (see below) it will be easy to plot the histogram.
You can probably use any format, but the effort to prepare the data will be higher (see for example here: Gnuplot: How to plot a bar graph from flattened tables).
Script:
### plotting histogram requires suitable input data format
reset session
$Data <<EOD
xxx 1 2 4
1000 14 10 9
4000 60 42 45
7000 80 70 50
EOD
set style histogram clustered gap 1
set style data histogram
set boxwidth 0.8 relative
set style fill solid 0.3
set xlabel 'Number of iterations'
set xtics out
set ylabel 'Time execution in seconds'
set grid x,y
set key top center title "Processors"
set offset 0,0,0.5,0
plot for [col=2:4] $Data u col:xtic(1) ti col
### end of script
Result:
You can use lc variable
plot test.data u 1:3:2 w boxes lc variable notitle
EDIT
notitle is not necessary, but it makes the plot seems better.
When Googling "horizontal gnuplot bar chart", the first result I could find http://www.phyast.pitt.edu/~zov1/gnuplot/html/histogram.html suggests rotating (!) the final bar chart which seems rather baroque. Nonetheless I tried the approach but the labels are cut off.
reset
$heights << EOD
dad 181
mom 170
son 100
daughter 60
EOD
set yrange [0:*] # start at zero, find max from the data
set boxwidth 0.5 # use a fixed width for boxes
unset key # turn off all titles
set style fill solid # solid color boxes
set colors podo
set xtic rotate by 90 scale 0
unset ytics
set y2tics rotate by 90
plot '$heights' using 0:2:($0+1):xtic(1) with boxes lc variable
Is there a better approach?
The link you are referring to is from approx. 2009. gnuplot has developed since then. As #Christoph suggested, check help boxxyerror.
Script: (edit: shortened by using 4-columns syntax for boxxyerror, i.e. x:y:+/-dx:+/-dy)
### horizontal bar graph
reset session
$Data << EOD
dad 181
mom 170
son 100
daughter 60
EOD
set yrange [0:*] # start at zero, find max from the data
set style fill solid # solid color boxes
unset key # turn off all titles
myBoxWidth = 0.8
set offsets 0,0,0.5-myBoxWidth/2.,0.5
plot $Data using (0.5*$2):0:(0.5*$2):(myBoxWidth/2.):($0+1):ytic(1) with boxxy lc var
### end of script
Result:
Addition:
what does
2:0:(0):2:($0-myBoxWidth/2.):($0+myBoxWidth/2.):($0+1):ytic(1) mean?
Well, it looks more complicated than it is. Check help boxxyerror. From the manual:
6 columns: x y xlow xhigh ylow yhigh
So, altogether:
x take value from column 2, but not so relevant here since we will use the xyerror box
y take pseudocolumn 0 which is line number starting from zero, check help pseudocolumns, but not so relevant here as well
xlow (0) means fixed value of zero
xhigh value from column 2
ylow ($0-myBoxWidth/2.), line number minus half of the boxwidth
yhigh ($0+myBoxWidth/2.), line number plus half of the boxwidth
($0+1) together with ... lc var: color depending on line number starting from 1
ytic(1): column 1 as ytic label
For some reason (which I don't know) gnuplot still doesn't seem to have a convenient horizontal histogram plotting style, but at least it offers this boxxyerror workaround.
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:
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'
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