I have a file with two columns
9 5
10 3
11 0
12 25
13 50
14 80
etc
What is the best way to plot bar char using gnuplot? Is using subprocess with gnuplot the best way? Ideally the graph should be in .pdf and in png as I want to put these on a website later on.
I would really appreciate your input/advise.
Here is an example, how to plot a bar chart with gnuplot using the plotting style with boxes
set terminal pngcairo size 1000,800 font ',12'
set output 'output.png'
set xlabel 'xlabel' font ',18'
set ylabel 'ylabel' font ',18'
set boxwidth 0.9
set style fill solid 0.3
set offset 0.5, 0.5, 10, 0
plot 'data.txt' with boxes linewidth 3 title ''
With the data you showed, this gives the following output image:
Related
I work with in-house benchmark tool. I use gnuplot (gnuplot 4.6 patchlevel 4) for visualization.
I need to represent results (method execution times for several runs) as stacked line chart, something like this:
Here is an excerpt from my .tsv data file:
Run MethodA MethodB MethodC
1 192 171 152
2 227 178 161
...
10 229 161 149
And the script I'm using:
#!/usr/bin/gnuplot -p
reset
clear
set terminal png size 640,480
set output "timings.png"
set key top left outside horizontal autotitle columnhead
set title "Third-party REST calls"
set xlabel "Run (ordinal)"
set xtics nomirror scale 0
set ylabel "Time (milliseconds)"
set ytics out nomirror
set grid ytics lt 0 lw 1 lc rgb "#bbbbbb"
set style data histogram
set style histogram rowstacked
set style fill solid border -1
set boxwidth 0.75
plot "timings.tsv" using 2:xticlabels(1) , "" using 3, "" using 4
I get the following result:
Yes, it's not a line chart but histogram (I need to represent percentage of execution time of each method). I need slightly different result (the same histogram, not with boxes but with lines which connect boxes tops and with filling below lines), like this:
I'm aware of approach with filledcurve's (for instance, described there Creating a Filled Stack Graph in GNUPlot), but in that approach you need to sum values explicitly.
Is it possible to draw filled areas instead of boxes via gnuplot, e.g. convert histogram into stacked line chart?
You do need to sum values explicitly, but this is not a big issue. You can script it easily:
firstcol=2
cumulated(i)=((i>firstcol)?column(i)+cumulated(i-1):(i==firstcol)?column(i):1/0)
plot "file.dat" using 1:(cumulated(4)), "" using 1:(cumulated(3)), "" using 1:(cumulated(2))
I have a CSV file with a data, and I need to plot a histogram (bars actually) using the data from given file. However, labels at axis X need to have Polish letters, for instance ąęćżźśłóń (or, uppercase, ĄĘĆŻŹŚŁÓŃ). I have already set the encoding with set encoding iso_8859_1 but still, the result does not look like what I want:
Here is my gnuplot script:
#!/usr/bin/gnuplot
set encoding iso_8859_1
set datafile separator "\t"
set termoption enhanced
set terminal postscript eps size 5.5, 5.62 enhanced color font 'Verdana,20' linewidth 2
set output '2008.eps'
unset key
set xtics nomirror rotate by -45 scale 0 font ",15"
set style data histogram
set boxwidth 0.2
set grid y
set yrange [ * : 20000]
set style fill solid border
plot '2008.csv' using 2:xticlabels(1) with boxes linecolor rgb "#00FF00", \
'' using 0:2:2 with labels center offset 0,1 notitle
And my data file:
Województwo Suma
Dolnośląskie 4997 4997
Kujawsko-Pomorskie 10710 10710
Lubelskie 8978 8978
Lubuskie 4631 4631
Łódzkie 12609 12609
The question is: what do I need to do to have Polish letters on axis X, and in a plot title (which is not available here, but I would like to add it later)? Thank you.
You should probably use UTF-8. Here's what I did:
set terminal epscairo enhanced color dashed rounded size 5.5, 5.62
set encoding utf8
set output '2008.eps'
unset key
set xtics nomirror rotate by -45 scale 0 font ",15"
set style data histogram
set boxwidth 0.2
set grid y
set yrange [*:20000]
set style fill solid border
plot '2008.csv' using 2:xticlabels(1) with boxes linecolor rgb "#00FF00", \
'' using 0:2:2 with labels center offset 0,1 notitle
(I copied the data from your question, which is in UTF-8 format but doesn't contain tab characters, so I didn't use set datafile separator "\t".)
This gave me the following result.
I'm using the epscairo terminal because it uses the pango library for rendering text which is based on UTF-8.
I am trying to plot a diagram using gnuplot. I want to put the hours of the day in the x-axis. I managed to do that with the following code:
set term postscript eps enhanced color "Times" 24
set output "DailyAvailability.eps"
set xtics rotate by -45 font ",18"
set xdata time
set timefmt '%Y-%m-%d %H'
set format x '%H:%M'
set ylabel "Number of peers"
set xlabel "Time of the day [in hours]"
set yrange [0:30]
set xrange ['2015-12-30 15:50':'2015-12-30 16:00']
set key right top #FFA500"
plot "intervals.dat" using 1:2 lc rgb "#000077" t "availability" w lines
This is my input data
"2015-12-30 15:59" 6
"2015-12-30 15:58" 10
"2015-12-30 15:57" 17
"2015-12-30 15:56" 18
"2015-12-30 15:55" 19
"2015-12-30 15:54" 20
"2015-12-30 15:53" 18
"2015-12-30 15:52" 28
"2015-12-30 15:51" 23
After executing the code, I get the diagram but with no line drawn in it. I tried to read other questions, but I cannot see any major differences between their code and mine Gnuplot date/time in x axis. I also checked for blank spaces in the input file, but since there is no error or warning messages, I cannot figure out what is going on. Can anybody see what I am missing here? Thanks for your time!
There are two tiny mistakes that make gnuplot say
Skipping data file with no valid points
Your time format is missing the minutes %M. Hence %H should be %H:%M
The quotation marks which are part of your time format are missing.
The solution is supposed to look like this
set timefmt '"%Y-%m-%d %H:%M"'
Then, I get
This code
1 function makegraph(A,B)
2 results=load(A);
3 time = results(:,3) - 1238370000;
4 firstTimeIndex = find(time >= (max(time) - 86400*7), 1);
5 results = results(max(1,firstTimeIndex-1):end, :);%Results now only containe s data from the last week
6 temp = results(:,3)-1238370000;
7 h=plot(temp,smooth(results(:,1)),':b','linewidth',2)
8 ylim([0 80])
9 xlim([max(temp)-(86400*7),max(temp)-1])
10 set(gca,'color','black')
11 set(gcf,'color','black') %get's rid of he axis alltogether
12 hold on
13 plot(temp, smooth(results(:,4)), 'r', 'linewidth', 2);
14 plot(temp, smooth(results(:,5)), 'g', 'linewidth', 2);
15 plot(temp, smooth(results(:,6)), 'm', 'linewidth', 2);
16 xlim([max(temp)-(86400*7),max(temp)-1])
17 set(gca,'XTick',[1:86400:(max(temp))+1])
18 set(gca,'XTickLabel',['Mon';'Tue';'Wed';'Thu';'Fri';'Sat';'Sun'])
19 print('-djpeg',B)
20 hold off
Saves this graph in the filename 'B'...
It works fine, but I'd like to put it in a different context, for which I need it to have a black background...
I have tried setting
set(gca,'color',[1 1 0])
set(gcf,'color',[1 1 0])
as described by Setting the background color of a plot in MATLAB using the command line?
and I've tried
whitebg(1,'k')
...and I'm getting nowhere -particualarly because sometimes when I try and play around with some of
set(gca,'color','black')
set(gcf,'color','black') settings, some of my plots disappear.
I'm deeply confused.. could someone tell me why the accepted answer at Setting the background color of a plot in MATLAB using the command line? isn't working here...?
Turns out that the commands were working within MATLAB, they just weren't working on the printed file because, according to http://www.mathworks.co.uk/help/matlab/ref/print.html....
By default, MATLAB changes the figure background color of printed
output to white, but does not change the color of uicontrols. If you
have set the background color, for example, to match the gray of the
GUI devices, you must set InvertHardcopy to off to preserve the color
scheme. To set InvertHardcopy on the current figure, use the command:
set(gcf,'InvertHardcopy','off')
So once I set set(gcf,'InvertHardcopy','off'), everything was peachy... thanks in particular to Molly, who put me on the right track...
I'm trying to print stacked histogram from gnuplot into black and white png. By this I mean I would like each region in the bar to be hatched or checked alongside the legend on the side; that way when it's printed people can still identify the regions.
I've tried the following but it just leaves me with big black blobs!
set term pngcairo mono size 750, 300
set output \"pies/interesting.png\"
set style data histograms
set style histogram rowstacked
set boxwidth 1 relative
set style fill solid 1 border -1
set yrange [0:100]
set ytics 10
set datafile separator \",\"
plot './functions-$MODE.csv.t' using 1 t \"\", for [i=9:13] '' using (100.*column(i)/column(15)) ti column(i)
How do I make my regions hatched?
Apologies for answering my own question....I've realised that a stacked histogram behaves like a normal histogram: thus if I use the styles found on this page: http://gnuplot.sourceforge.net/demo/fillstyle.html I can customise to how I would like: setting "set style fill pattern border" :
set term pngcairo mono size 750, 300
set output \"pies/interesting.png\"
set style data histograms
set style histogram rowstacked
set boxwidth 1 relative
set style fill pattern border
set datafile separator \",\"
plot './functions-$MODE.csv.t' using 1 t \"\", for [i=9:13] '' using (100.*column(i)/column(15)) ti column(i)
Results in the desired effect.