I'm just taking the first look at gnuplot today and using the histogram example, I wanted to build a small example as from the tutorial, only I changed the input numbers from 50,000 something to 100-range and it is not visualized correctly.
Here's the dat file
Region Denmark Netherlands Norway Sweden
1891-1900 500 400 300 200
And this is the gnuplot script
set terminal pngcairo
set output 'histograms.2.png'
set boxwidth 0.9 absolute
set style fill solid 1.00 border lt -1
set key inside right top vertical Right noreverse noenhanced autotitles nobox
set style histogram clustered gap 5 title offset character 0, 0, 0
set datafile missing '-'
set style data histograms
set xtics border in scale 0,0 nomirror rotate by -45 offset character 0, 0, 0
set xtics norangelimit font ",8"
set xtics ()
set title "US immigration from Northern Europe\n(same plot with larger gap between clusters)"
set yrange [ 0.00000 : 3000. ] noreverse nowriteback
i = 22
plot 'immigration.dat' using 1:xtic(1) ti col, '' u 2 ti col, '' u 3 ti col, '' u 4 ti col
As seen in here:
the first column is wrongly visualized. any ideas?!
I think you want:
plot 'immigration.dat' using 2:xtic(1) ti col, '' u 3 ti col, '' u 4 ti col, '' u 5 ti col
In your version, gnuplot is interpreting the data in the first column (1891-1900) as a number (1891). You can also see this by carefully looking at the key -- The red bar corresponds to Region.
Related
Output Should be something like this
can anyone please help me with a sample code to build histogram for below data. I am very new to this and would really appreciate some help.
Date_Stat Total Success Gen_decline Failure_incomplete
01.05.2018 42045 39164 2096 785
02.05.2018 33721 30857 1727 1137
03.05.2018 28159 26042 1513 604
It doesn't look to good, but it is a start. First I saved the data into a file "so-dat.txt" pretty much as shown. Then I used this gnuplot script.
set boxwidth 0.9 absolute
set style fill solid 1.00 border lt -1
set key right top vertical Right noreverse noenhanced autotitle nobox
set style histogram clustered gap 1 title textcolor lt -1
set datafile missing '-'
set style data histograms
set xtics border in scale 0,0 nomirror rotate by -45 autojustify
set xtics norangelimit
set xtics ()
set title "data"
set yrange [ 0.00000 : 45000. ] noreverse nowriteback
## Last datafile plotted: "immigration.dat"
plot 'so-dat.txt' using 2:xtic(1) ti col, '' u 3 ti col, '' u 4 ti col, '' u 5 ti col
That creates a bar chart with 3 clusters (by date) of four columns (Total Success Gen_decline failure_incomplete.)
To make the key horizontal.
set key right horizontal noenhanced autotitle nobox
Or even set the key above. Although that is above the title.
set key above horizontal autotitle nobox
I have data I would like to plot in a histogram style with a "cumulated" curve on top. I have the following problem:
My data consists of one column with the categories ("discharge") and one column with the quantity of values ("probability") that belong to the respective category. The last value of the category-column is ">100" summarizing all power plants that have a bigger discharge than the last numeric value ("100 m^3/s"). I have not found a solution to plot this last category and the respective values with the command plot 'datafile.dat' using 1:2 with boxes ... because (as I assume) in this case only numerical values are read out for the x-ticlabels, so the last category is missing. If
I plot it with this command plot 'datafile.dat' using 2:xtics(1) with boxes ... I get the last category ">100" plotted just fine.
BUT: if I use the latter command the x-axis labels appear in the normal font size. Even though I have the line set format x '\footnotesize \%10.0f' in my code.
I have read about explicit labels in the plotcommand line that overwrite format style which was set before but was not able to adapt it to my code.
Changing ytic font size in gnuplot epslatex (multiplot)
Do you have an idea how to do this?
Excel screenshot to visualize what I want to achieve
'datafile.dat'
discharge probability cumulated
10 20 20%
20 10 10%
30 5 5%
40 6 6%
50 4 4%
60 12 12%
70 8 8%
80 15 15%
90 20 20%
100 6 6%
>100 4 4%`
[terminal=epslatex,terminaloptions={size 15cm, 8cm font ",10"}]
set xrange [*:*]
set yrange [0:20]
set y2range [0:100]
set xlabel 'Discharge$' offset 0,-1
set ylabel 'No. of power plants' offset 10.5
set y2label 'Cumulated probability' offset -10
set format xy '$\%g$'
set format x '\footnotesize \%10.0f'
set format y '\footnotesize \%10.0f'
set format y2 '\footnotesize \%10.0f'
set xtics rotate by 45 center offset 0,-1
set style fill pattern border -1
set boxwidth 0.3 relative
set style line 1 lt 1 lc rgb 'black' lw 2 pt 6 ps 1 dt 2
plot 'datafile.dat' using 1:2 with boxes axes x1y1 fs pattern 6 lc black notitle, \
'datafile.dat' using 1:3 with linespoints axes x1y2 ls 1 notitle
I am confused by your datafile; the numbers in the third column do not seem to be cumulative, and do not add up to 100%. Here is a solution that uses only the first two columns of your file:
set term epslatex standalone header "\\usepackage[T1]{fontenc}"
set output 'test.tex'
stats "datafile.dat" using 2
total = STATS_sum
set xlabel "Discharge" offset 0, 1.5
set xtics rotate
set ylabel "No. of power plants"
set ytics nomirror
set yrange [0:*]
set y2label "Cumulative probability"
set y2tics
set y2range [0:]
set boxwidth 0.3 relative
set style line 1 lt 1 lc rgb 'black' lw 2 pt 6 ps 1 dt 2
plot \
'datafile.dat' using 2:xtic("\\footnotesize " . stringcolumn(1)) with boxes axes x1y1 fs pattern 6 lc black notitle, \
'datafile.dat' using ($2/total) smooth cumulative with linespoints axes x1y2 ls 1 notitle
set output
The trick is to add the latex command \footnotesize in front of each label in the using command. It also first computes the total number of power plants so that it can compute probabilities, and computes cumulative values with the smooth cumulative option.
yesteraday I made a similar question (this one). I could not display the value on top of bar in a gnuplot histogram. I lost many time because I couldn't find really good documentation about it, and I only can find similar issues on differents websites.
I lost many time with that but fortunately someone give me the solution. Now I am having a similar issue with an histogram with two bars, in which I have to put on top of both bars its value. I am quite near, or that is what I think, but I can't make it work properly. I am changing the script and regenerating the graph many times but I am not sure of what I am doing.
script.sh
#!/usr/bin/gnuplot
set term postscript
set terminal pngcairo nocrop enhanced size 600,400 font "Siemens Sans,8"
set termoption dash
set output salida
set boxwidth 0.8 absolute
set border 1
set style fill solid 1.00 border lt -1
set key off
set style histogram clustered gap 1 title textcolor lt -1
set datafile missing '-'
set style data histograms
set xtics border in scale 0,0 nomirror autojustify
set xtics norangelimit
set xtics ()
unset ytics
set title titulo font 'Siemens Sans-Bold,20'
set yrange [0.0000 : limite1] noreverse nowriteback
set y2range [0.0000 : limite2] noreverse nowriteback
show style line
set style line 1 lt 1 lc rgb color1 lw 1
set style line 2 lt 1 lc rgb color2 lw 1
## Last datafile plotted: "immigration.dat"
plot fuente using 2:xtic(1) ls 1 ti col axis x1y1, '' u 3 ls 2 ti col axis x1y2, '' u 0:2:2 with labels offset -3,1 , '' u 0:2:3 with labels offset 3,1
I am modifying the last code line, because is here where I set the labels. I have been able to show both labels, but in bad positions, I have also been able to show one of the labels in the right position but no the other. I have been able to show almost everything but the thing that I want. This is the graph that generates the script.
output.png
This is the source file that I use for generating the graph
source.dat
"Momento" "Torre 1" "Torre 2"
"May-16" 1500.8 787.8
"Jun-16" 1462.3 764.1
"Jul-16" 1311.2 615.4
"Ago-16" 1199.0 562.0
"Sep-16" 1480.0 713.8
"Oct-16" 1435.1 707.8
And that's the command that I execute with the parameters set
gnuplot -e "titulo='Energía consumida por torre (MWh)'; salida='output.png'; fuente='source.dat'; color1='#FF420E'; color2='#3465A4'; limite1='1800.96'; limite2='945.36'" script.sh
I think that is quite obvious what I am pretending, can someone help me?
Lots of thanks in advance.
Your script has several problems, the missing ti col is only one of them. (You can also use set key auto columnheader, then you must not give that option every time).
Don't use both y1 and y2 axis if you want to compare the values! Otherwise the correct bar heights are only a matter of luck...
Understand, how gnuplot positions the histogram bars, then you can exactly locate the top center of each bar. If you only use offset with char values (which is the case when you give only numbers), then your script will break as soon as you add or remove a data row.
The histogram clusters start at x-position 0, and are positioned centered at integer x values. Since you have two bars in each cluster and a gap of 1, the center of the first bar is at ($0 - 1/6.0) (= 1/(2 * (numberOfTorres + gapCount))), the second one at ($0 + 1/6.0):
set terminal pngcairo nocrop enhanced size 600,400 font ",8"
set output 'output.png'
set title 'Energía consumida por torre (MWh)' font ",20"
set boxwidth 0.8 absolute
set border 1
set style fill solid 1.00 border lt -1
set style histogram clustered gap 1 title textcolor lt -1
set style data histograms
set xtics border scale 1,0 nomirror autojustify norangelimit
unset ytics
set key off auto columnheader
set yrange [0:*]
set offset 0,0,graph 0.05,0
set linetype 1 lc rgb '#FF420E'
set linetype 2 lc rgb '#3465A4'
# dx = 1/(2 * (numberOfTorres + gap))
dx = 1/6.0
plot 'source.dat' using 2:xtic(1),\
'' u 3,\
'' u ($0 - dx):2:2 with labels,\
'' u ($0 + dx):3:3 with labels
Now, starting at the bars center you can safely use offset to specify only the offset relative to the bars top center:
plot 'source.dat' using 2:xtic(1),\
'' u 3,\
'' u ($0 - dx):2:2 with labels offset -1,1 ,\
'' u ($0 + dx):3:3 with labels offset 1,1
A second option would be to use the label's alignment: The labels of the red bars are right aligned at the bars right border, the labels of the blue bars are left aligned at the bars left border:
absoluteBoxwidth = 0.8
dx = 1/6.0 * (1 - absoluteBoxwidth)/2.0
plot 'source.dat' using 2:xtic(1),\
'' u 3,\
'' u ($0 - dx):2:2 with labels right offset 0,1 ,\
'' u ($0 + dx):3:3 with labels left offset 0,1
In any case, both options make your script more robust against changes of the input data.
This looks better :
plot fuente using 3:xtic(1) ls 1 ti col axis x1y1, '' u 3 ls 2 ti col axis x1y2, '' u ($0-1):3:3 with labels offset -3,1 , '' u ($0-1):2:2 with labels offset 3,1
You had 2 plots commands: only the first one was displayed.
Also, script.sh should be a bash script. This is a gnuplot script, so it should have another extension.
The problem is the ti col tab. You need to put it in every option, including labels and not only in bars. The right code is:
plot fuente using 2:xtic(1) ls 1 ti col, '' u 3 ls 2 ti col, '' u 0:2:2 ti col with labels offset -3,1 , '' u 0:3:3 ti col with labels offset 3,1
And that's how the picture is displayed now:
You can also avoid ti col and that is how it would look:
Hi I'm new with gnuplot
I'm trying to display a bar graph like this one:
to display this data:
#Float ADDs Float Muls Int ADDs Int MULs
14336 20480 19450 2084
8960 14336 12902 3071
using this script that i modified :
set boxwidth 0.9 absolute
set style fill solid 1.00 border lt -1
set key inside right top vertical Right noreverse noenhanced autotitle nobox
set style histogram clustered gap 5 title textcolor lt -1
set datafile missing '-'
set style data histograms
set xtics border in scale 0,0 nomirror rotate by -45
set xtics norangelimit
set xtics ()
set title "Number of operation : Radix-2 VS Radix-4"
set yrange [ 0.00000 : 200000. ] noreverse nowriteback
x = 0.0
i = 22
plot 'dataop.dat' using "Float ADDs":xtic(1) ti col, '%lf,%lf,%lf' u "Float Muls" ti col, '%lf,%lf,%lf' u Int ADDs ti col, '%lf,%lf,%lf' u "Int MULs" ti col
can someone help me ?
Here's a version of a slightly modified data file and gnuplot script that will give you a plot, although I'm not quite sure if it's exactly what you are looking for.
Datafile:
Float_ADDs "Float Muls" IADDs IMULs
14336 20480 19450 2084
8960 14336 12902 3071
Changes:
Do not put a '#' before the header, otherwise gnuplot treats the line as comment and ignores it.
IF you want to use multi-words column headers you must put them in quotation marks like "Float Muls", alternatively you could use an underscore like Float_ADDs, or just shorten it to one word like IADDs and IMULs
Script:
set boxwidth 0.9 absolute
set style fill solid 1.00 border lt -1
set key inside right top vertical Right noreverse noenhanced autotitle nobox
set style histogram clustered gap 5 title textcolor lt -1
set datafile missing '-'
set style data histograms
set xtics border in scale 0,0 nomirror rotate by -45
set xtics norangelimit
set xtics
set title "Number of operation : Radix-2 VS Radix-4"
set yrange [ 0.00000 : 200000. ] noreverse nowriteback
plot 'dataop.dat' using "Float_ADDs":xtic(1) ti col,'' u "Float Muls" ti col, '' u "IADDs" ti col, '' u "IMULs" ti col
Changes:
Mostly modified the plot command
Use '' to add a dataseries from the same file as specified for the first dataseries.
Modified the column names to match the datafile, alternatively you could use a column index and hardcode the title.
I want to fill a bar with both a color background and a pattern. Is it possible in Gnuplot?
I am using Gnuplot 4.6.5
The code I have now:
# set terminal pngcairo transparent enhanced font "arial,10" fontscale 1.0 size 500, 350
# set output 'histograms.2.png'
set boxwidth 0.9 absolute
set style fill solid 1.00 border lt -1
set key inside right top vertical Right noreverse noenhanced autotitles nobox
set style histogram clustered gap 1 title offset character 0, 0, 0
set datafile missing '-'
set style data histograms
set xtics border in scale 0,0 nomirror rotate by -45 offset character 0, 0, 0 autojustify
set xtics norangelimit font ",8"
set xtics ()
set title "US immigration from Northern Europe\nPlot selected data columns as histogram of clustered boxes"
i = 22
set yrange [0:2000]
set style line 1 lc rgb 'orange';
set style line 2 lc rgb 'pink';
plot for [i=2:7] 'data.dat' using i:xtic(1) ti col ls i%2+1;
The data file:
Region Denmark France Demark-Women France-women Demark-man France-men
1891-1900 1000 1100 500 600 500 500
1901-1910 1500 1600 1000 600 500 1000
Here are the links to download the script: https://dl.dropboxusercontent.com/u/45318932/histograms2.plt and data file: https://dl.dropboxusercontent.com/u/45318932/data.dat
The script gives me:
What I want is:
It would be much appreciated if someone can help me improve the code to produce the second figure. Thanks.
That one is very tricky because you cannot change the background color of the fill patterns. And by default the background color of the patterns is white, and not transparent or empty.
The only terminal which can be manipulated adequately is the lua tikz terminal. Here, I first draw all the color boxes, and later in a second iteration the fill patterns. To have a new iteration, I use the newhistogram option, which however causes a gap in the legend.
To remove the white background of the fill patterns, I remove the relevant parts from the output stream with sed. Quite hacky, but it works:
set terminal lua tikz standalone size 5in, 3in color
set output '| sed ''s/\\gpfill{color=gpbgfillcolor}//g'' > histograms.tex'
set boxwidth 0.9 absolute
set style fill solid 1.00 border lt -1
set key inside right top vertical Right noreverse noenhanced autotitles nobox
set style histogram clustered gap 1 title offset character 0, 0, 0
set datafile missing '-'
set style data histograms
set xtics border in scale 0,0 nomirror rotate by -45 offset character 0, 0, 0 autojustify
set xtics norangelimit font ",8"
set xtics ()
set title "US immigration from Northern Europe\nPlot selected data columns as histogram of clustered boxes"
i = 22
set yrange [0:2000]
set xrange [-1:2]
set style line 1 lc rgb 'orange';
set style line 2 lc rgb 'pink';
plot for [i=2:7] 'data.dat' using i:xtic(1) ti columnhead(i > 3 ? 10 : i) ls i%2+1 fillstyle solid noborder,\
newhistogram at -1, \
'' using 2 ti 'total' lt -1 fillstyle empty,\
'' using 3 notitle lt -1 fillstyle empty,\
'' using 4 title 'women' lt -1 fillstyle pattern 5,\
'' using 5 notitle lt -1 fillstyle pattern 5,\
'' using 6 title 'men' lt -1 fillstyle pattern 6,\
'' using 7 notitle lt -1 fillstyle pattern 6
set output
system('pdflatex histograms.tex')
Result with 4.6.5:
Just found out, that you can specify the patterns to have no background color like
... fillstyle pattern 6 transparent
For which terminals that works depends on the gnuplot version:
plot x with filledcurves x1 fillstyle solid fc rgb '#990000',\
x with filledcurves x1 fillstyle pattern 4 transparent lc rgb 'white'
Result (with svg terminal and version 4.6.5):