I would like to make a bar graph that displays each bar as the bottom of the bar being y-min and the top of the bar being y-max. In addition I'd like each bar to have its own color fill and custom tics where xtic(1). Thank you
Similar to this below:
How to make range bar graphs in gnuplot?
ex.
#number #y-min #y-max #rgb
1 2 5 1
2 2.5 5.4 2
3 4 6 3
4 4.3 7 4
Here is what I ended up doing in case someone else needs it
set termoption font ",22"
boxwidth = 0.5
set style fill solid
set xtics nomirror
set ytics nomirror
set xtics font "{/:Bold,22}"
set ytics font "{/:Bold,22}"
set xlabel "Structure"
set xlabel font "{/:Bold,30}"
set ylabel "Potential (V vs. RHE)"
set ylabel font "{/:Bold,30}"
set xrange [-1:4.5]
set yrange [0:7]
set arrow from -1,2.5 to 4.5,2.5 nohead lc rgb 'black' dt 3
plot 'poten-range-plot' u 0:(($2+$3)/2.):(boxwidth/2.):(($3-$2)/2.):4:xtic(1) w boxxyerrorbars notitle lw 3 lc variable, 1/0 t "Pt (111)" lt 1 lc rgb 'black'
I have a CSV file looking like:
frameNo dataSeg paritySeg frameType
0 17 3 k
1 2 1 d
2 3 1 d
3 3 1 d
4 3 1 d
5 2 1 d
6 3 1 d
7 3 1 d
8 4 1 d
I'm able to plot stacked column diagram showing number of data and parity segments per frame. Looks like this:
What I'd like to add to it, however, is paint differently those columns (both data and parity) which have "k" marker in the last column. Basically, distinguish between two categories - "d" and "k".
Is that possible using gnuplot?
Here's the script I'm using:
set style histogram rowstacked;
set style data histograms;
set style fill solid;
set datafile separator "\t";
set terminal png size 2500,1500 enhanced font ",30";
set title "";
set tics font ",25";
set xlabel "Frame #" font ",25";
set ylabel "# of segments" font ",25";
set key outside;
set xrange [0:];
plot "segments.csv" using 2 t "Data", "" using 3 t "Parity";'
You could impose a custom condition on the columns being plotted and supply an invalid value (signaling to skip the particular data point) if this condition is not met:
set terminal pngcairo size 1200,600 enhanced font ",30";
set output 'test.png'
set style histogram rowstacked;
set style data histograms;
set style fill solid;
#set datafile separator "\t";
set title "";
set tics font ",25";
set xlabel "Frame #" font ",25";
set ylabel "# of segments" font ",25";
set key outside;
set xrange [0:];
fName = 'segments.csv'
plot \
fName using (strcol(4) eq 'd'?$2:1/0) t "Data d" lc rgb '#666666', \
fName using (strcol(4) eq 'd'?$3:1/0) t "Parity d" lc rgb '#ff0000', \
fName using (strcol(4) eq 'k'?$2:1/0) t "Data k" lc rgb '#000000', \
fName using (strcol(4) eq 'k'?$3:1/0) t "Parity k" lc rgb '#990000'
this would give (using the sample data in your question):
I've a csv data file like this:
Sensor1;value;iteration
Sensor2;value;iteration
Sensor2;value;iteration
Sensor1;value;iteration
Sensor2;value;iteration
Can I plot two different lines in base of my 1st col value? one for Sensor1 and another for Sensor2 in same plot.
Now I plot all data as follow:
set terminal jpeg
set output 'testimage.jpeg'
set autoscale # scale axes automatically
unset log # remove any log-scaling
unset label # remove any previous labels
set xtic auto # set xtics automatically
set ytic auto # set ytics automatically
set datafile separator ";"
set xrange [1:10000]
set yrange [3000:5000]
plot "result_test_day_1.csv" using 5:3:(stringcolumn(1) eq "Sensor1"? $2:1/0) title "a" lc rgb "blue" with lines
plot "result_test_day_1.csv" using 5:3:(stringcolumn(1) eq "Sensor2"? $2:1/0) title "b" lc rgb "red" with lines
Assuming to have the following 4 datasets:
a.csv
1,1
2,3
3,5
5,6
6,9
7,9
8,10
9,12
10,13
b.csv
1,1
2,5
3,10
5,15
6,20
7,25
8,30
9,35
10,40
c.csv
1,1
2,10
3,100
5,1000
6,2000
7,5000
8,10000
9,20000
10,50000
d.csv
1,1
2,20
3,300
5,5000
6,9000
7,10000
8,15000
9,30000
10,100000
In Gnuplot I've tried to run the command stats on each of them to get the maximum value for x and y (i.e., columns 1 and 2) and to set the corresponding xrange & yrange. Unfortunately, the result is not the one I've expected.
Here is the full script:
#!/usr/bin/env gnuplot
set terminal latex
set term pngcairo enhanced size 1500,800
set output 'plot.png'
set multiplot layout 2,2
set xlabel 't' font ',16'
set ylabel '#pkt' font ',16'
set grid xtics lt 0 lw 1 lc rgb "#333333"
set grid ytics lt 0 lw 1 lc rgb "#333333"
set xtics font ',14'
set ytics font ',14'
set key font ',12'
set title font ',20'
set datafile separator ','
###
set title '(a)'
stats "a.csv" using 1:2 name "a"
set xrange [0:a_max_x]
set yrange [0:a_max_y+a_max_y*0.5]
plot "a.csv" using 1:2 title 'v1' with lines linewidth 3 linecolor rgb 'blue'
###
set title '(b)'
stats "b.csv" using 1:2 name "b"
set xrange [0:b_max_x]
set yrange [0:b_max_y+b_max_y*0.5]
plot "b.csv" using 1:2 title 'v1' with lines linewidth 3 linecolor rgb 'blue'
###
set title '(c)'
stats "c.csv" using 1:2 name "c"
set xrange [0:c_max_x]
set yrange [0:c_max_y+c_max_y*0.5]
plot "c.csv" using 1:2 title 'v1' with lines linewidth 3 linecolor rgb 'blue'
###
set title '(d)'
stats "d.csv" using 1:2 name "d"
set xrange [0:d_max_x]
set yrange [0:d_max_y+d_max_y*0.5]
plot "d.csv" using 1:2 title 'v1' with lines linewidth 3 linecolor rgb 'blue'
###
unset multiplot
and the result:
As you can see, maximum values in the plots b, c and d are not correct. Indeed, the verbose output of stats returns:
[...]
Maximum: 10.0000 [8] 13.0000 [8]
[...]
Maximum: 5.0000 [3] 15.0000 [3]
[...]
Maximum: 2.0000 [1] 10.0000 [1]
[...]
Maximum: 1.0000 [0] 1.0000 [0]
[...]
Apparently, only stats for the plot a is right. Is there anything wrong in my script?
You need you reinitialize xrange and yrange after setting them each time, because otherwise stats finds some of you points outside the range you have previously set and does not take them into account. It's the last line below:
set title '(a)'
stats "a.csv" using 1:2 name "a"
set xrange [0:a_max_x]
set yrange [0:a_max_y+a_max_y*0.5]
plot "a.csv" using 1:2 title 'v1' with lines linewidth 3 linecolor rgb 'blue'
set xrange [*:*] ; set yrange [*:*] # <--- This line after each plot will fix your issue
In your case there is no need to use stats in order to set the ranges.
Your requirements are:
Use tight limits for the xrange and the yrange. You get this with set autoscale fix.
Extend the maximum of the yrange by 50%. That is achieved with set offsets 0,0,graph 0.5,0:
#!/usr/bin/env gnuplot
set term pngcairo enhanced size 1500,800
set output 'plot.png'
set multiplot layout 2,2
set xlabel 't' font ',16'
set ylabel '#pkt' font ',16'
set grid xtics ytics lt 0 lw 1 lc rgb "#333333"
set tics font ',14'
set key font ',12'
set title font ',20'
set datafile separator ','
set style data lines
set style line 1 linewidth 3 linecolor rgb 'blue'
###
set title '(a)'
set autoscale fix
set offset 0,0,graph 0.5,0
plot "a.csv" using 1:2 title 'v1' linestyle 1
###
set title '(b)'
plot "b.csv" using 1:2 title 'v1' linestyle 1
###
set title '(c)'
plot "c.csv" using 1:2 title 'v1' linestyle 1
###
set title '(d)'
plot "d.csv" using 1:2 title 'v1' linestyle 1
###
unset multiplot
One further comment: If you're going to use a LaTeX-based terminal for your actual image, don't use latex, but rather epslatex, cairolatex, context or lua tikz, which are all much better regarding the supported features and quality.
I am using gnuplot to draw a histogram of a series of RAM measurements I performed.
However, I want it to display the values that are stored in Bytes in CSV files in KB.
I divided the respective columns by 1024, but gnuplot simply ignores that.
Below you see the template that is changed by a script to have meaningful file names for CSVFILE and PSFILE and then fed into gnuplot.
set style data histogram
set style histogram errorbars gap 1
set xlabel "nodes"
set ylabel "memory (KB)"
set key left box
set datafile separator ","
set terminal postscript landscape
set output 'PSFILE'
plot 'CSVFILE' using ($2/1024):($3/1024):xtic(1) ti col lt -1 fs pattern 1,\
'' using ($4/1024):($5/1024):xtic(1) ti col lt -1 fs pattern 2,\
'' using ($6/1024):($7/1024):xtic(1) ti col lt -1 fs pattern 4,\
'' using ($8/1024):($9/1024):xtic(1) ti col lt -1 fs pattern 6,\
'' using ($10/1024):($11/1024):xtic(1) ti col lt -1 fs pattern 5,\
'' using ($12/1024):($13/1024):xtic(1) ti col lt -1 fs pattern 7,\
'' using ($14/1024):($15/1024):xtic(1) ti col lt -1 fs pattern 3
So what does not work is the /1024. Any ideas how to do that?
Changing the CSV files instead came to my mind, yes, but they are a lot, and I would have to write a script to change all cells, which I definitely do not fancy to do.
Okay, the solution was trivial. I just had to enclose the $2 values in extra braces, like ($2)/1024.