I could not find a solution to the following issue I am facing. All SO questions on multi-axis talk about line plots, but I am looking for histograms.
The y-range for the bars are different, so one set of bars are not really seen because of the scale. Here is the data:
Metric A B
M1 0.613416301 0.543734744
M2 0.000195961 0.000100190
Here is the MWE:
reset
set term postscript eps size 5.5,4.5 enhanced color font 'Arial-Bold' 25
set out 'histplot.eps'
set key right
set style histogram cluster gap 2
set style data histograms
set style fill pattern 1.00 border
set y2range [0.0001:0.0002]
plot 'histplot.dat' using 2 ti col, '' u 3:xticlabels(1) ti col
quit
This is the sample output (one set of bars over M2 is not seen):
What I prefer is to have a second y-axis (to the right side of the plot) with a range appropriate to the second row of my data file. Is this possible? Any help is greatly appreciated.
Normally you can plot severyl histograms beneath each other using newhistogram. However, it seems like this is buggy when using patterns as fillstyle:
reset
set style histogram cluster gap 1
set style data histograms
set style fill pattern 1.00 border
set yrange [0:*]
set ytics nomirror
set y2range [0:*]
set y2tics
set key right autotitle columnheader
plot 'histplot.dat' u 2 every ::::0, '' u 3:xtic(1) every ::::0,\
newhistogram lt 1 at 1,\
'histplot.dat' u 2 every ::1::1 axes x1y2, '' u 3:xtic(1) every ::1::1 axes x1y2
Alternatively you can use multiplot and plot the two histograms directly beneath each other:
reset
set style histogram cluster gap 1
set style data histograms
set style fill pattern 1.00 border
set yrange [0:*]
set ytics nomirror
set multiplot layout 1,2
set rmargin at screen 0.5
set lmargin 9
unset key
plot 'histplot.dat' using 2 every ::::0 ti col, '' u 3:xticlabels(1) every ::::0 ti col
set rmargin 9
set lmargin at screen 0.5
unset ytics
set y2range [0:*]
set y2tics
set key right
plot '' using 2 every ::1::1 axes x1y2 ti col, '' u 3:xtic(1) every ::1::1 axes x1y2 ti col
unset multiplot
If you don't want the separating black line, you can use set border 7 for the first and set border 13 for the second plot.
Related
My gnuplot script plot a bar graph for 2D data either in monochrome or color format:
set term pngcairo size 800,600
set termoption noenhanced
set tics font "Helvetica,10"
#set xtics noenhanced
set ylabel "Fraction, %"
set xlabel "H-bond donor/aceptor, residue"
set yrange [0:1]
set ytics 0.1
set grid y
set key off
set boxwidth 0.9
set style fill solid 0.5
# TWO OPTIONS FOR BAR VISUALISATIONS!! NB: ADD HERE TRIGGER FROM COLOR_DATA TRIGGER
# 1 - use it with non-colored bars"
#plot "\$data" using 0:2:xtic(1) with boxes, "" using 0:2:2 with labels offset 0,1
# 2 - or use it with colored bars:
plot \$data using 0:2:3:xtic(1) with boxes lc rgb var, \
'' using 0:2:2 with labels offset 0,1
The problem when I have just one bar, one the graph it occupiers all the graph on X:
Would it be possible to set some minimum dimension for the bars to make the dimensions of a single bar similar for a situations with two bars, for instance:
My understanding is the following: if you have only one box:
maybe gnuplot tries to autoscale and the automatic boxwidth is small relative to the autorange (hence just a thin line).
if you set a certain boxwidth, autoscale with scale to the given boxwidth (hence the graph filled with the box).
you could set a fixed xrange, but then you are loosing the benefits of autoscale. Instead you can use set offets (check help offsets).
if you have more than 1 box autoscale will work.
Script:
### boxwidth with boxes style
reset session
$Data1 <<EOD
1 Abc
EOD
$Data2 <<EOD
1 Abc
2 Xyz
EOD
set style fill solid 0.3
set key out
set rmargin screen 0.7
set yrange[0:]
set ytics 0.5
set multiplot layout 4,1
plot $Data1 u 0:1:xtic(2) w boxes ti "No special settings"
set boxwidth 0.9
plot $Data1 u 0:1:xtic(2) w boxes ti "set boxwidth"
set offsets 1,1,0,0
plot $Data1 u 0:1:xtic(2) w boxes ti "set offsets"
set offsets 0,0,0,0
plot $Data2 u 0:1:xtic(2) w boxes ti "more than 1 box"
unset multiplot
### end of script
Result:
I have a dataset (show-errorbar.dat) containing:
Model# DE IE Error
Apple -4.6 -128.9538 4.0
Huawei -5.2 -176.6343 5.3
One-Pro -5.2 -118.1106 3.2
#!/usr/bin/gnuplot
#set terminal pdfcairo enhanced color font 'Helvetica,12' linewidth 0.8
set terminal png
set output 'BrandError.png'
set boxwidth 1.0 relative
set bmargin 5
set style fill solid border -1
set xtic rotate by -45 scale 0
#set auto x
set style line 81 lt 0 lc rgb "#808080" lw 0.5
set grid xtics
set grid ytics
set grid mxtics
set grid mytics
set grid back ls 81
set arrow from graph 0,first -4.6 to graph 1, first -4.6 nohead lw 2 lc rgb "#000000" front
set border 11
set border lw 2.0
set xtics font ",11"
set ytics font ",14"
set tics out
set ytics nomirror
set y2tics
set y2tics font ",14"
set mxtics 10
set mytics 2
set my2tics 2
set yrange [-10:0]
set y2range [-260:0]
set key left bottom
set y2label offset -2
set ylabel offset 2
set ylabel 'DE' tc rgb "red"
set y2label 'IE' tc rgb "green"
set style data histograms
set style histogram cluster gap 2
set linetype 2 lc rgb 'red'
set linetype 3 lc rgb 'yellow'
set linetype 4 lc rgb 'green'
plot 'show-errorbars.dat' using 2 ti 'DE' lc 2 axis x1y1, '' u 3:xticlabels(1) ti 'IE' lc 4 axis x1y2
set output
enter image description here
I would like to plot a histogram comparing DE vs IE and also show error bars (data in column 4) for the IE values.
Please any help on how to go about it.
There is a variant histogram style for exactly that purpose
set style histogram errorbars gap 2 {lw W}.
Here is the help section from the docs:
The `errorbars` style is very similar to the `clustered` style, except that it
requires additional columns of input for each entry. The first column holds
the height (y value) of that box, exactly as for the `clustered` style.
2 columns: y yerr bar extends from y-yerr to y+err
3 columns: y ymin ymax bar extends from ymin to ymax
The appearance of the error bars is controlled by the current value of
`set errorbars` and by the optional <linewidth> specification.
Updated answer
Notes:
You can't mix axis choice within a single histogram. So I have removed the axes x1y1 and axes x1y2 from the plot command. Since you have explicitly given the range for both y1 and y2, the plot border and labels are not affected.
However since the green bars are now being plotted against y1, we have to scale them so that the y2 axis labels apply. So the column 3 and column 4 values will be divided by 26, which is (y2 range) / (y1 range)
In "histogram errorbars" mode each plot component looks for an extra column of data to determine the size of the errorbar. Since your column 2 data has no corresponding column of errors, we dummy it up to use all a constant not-a-number (no data) value: (NaN)
Your data contains a line of columnheaders, which could confuse the program if it thinks this is a line of data. There are a number of ways you can tell the program to skip this line; I have used set key autotitle columnhead for convenience and because it is supported by old versions of gnuplot. If you have a current version it would be better to use instead set datafile columnheaders.
I have kept all of your commands except that the plot command is replaced by the following 3 lines:
set style histogram errorbars gap 2 lw 1.5
set key autotitle columnhead
plot 'show-errorbars.dat' using 2:(NaN) ti 'DE' lc 2, '' u ($3/26.):($4/26.):xticlabels(1) ti 'IE' lc 4
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 a gnuplot script
set terminal qt size 850,500 enhanced font 'Verdana,12' persist
set boxwidth 0.9 absolute
set ylabel "Duration in milliseconds" #font "Arial 14"
set tics font "Monospaced,bold 14"
set style fill solid 1.00 border lt -1
set key inside right top vertical Right noreverse noenhanced autotitle nobox
set style histogram cluster gap 1 title textcolor lt -1
set minussign
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 "Integer d-ary heap performance"
set yrange [0:*]
set style line 1 lt 1 lc rgb "#000000"
set style line 2 lt 2 lc rgb "green"
plot 'integer_heap_benchmark_dary.dat' using 2:xtic(1) linecolor rgb "#5555ff" title col, \
'' using 3:xtic(1) linecolor rgb "#f4dc42" title col, \
'' using 4:xtic(1) title col
which looks like this:
What I want to achieve is:
Move each x-axis label a little bit to the left so that it "points" to the center of each cluster,
Change the font and size of the x-axis labels.
I have put an effort to find the answers on my own, yet without any success.
Try something like
set tics font "Courier,24"
to set the font.
To center the labels, try something like
set xtics offset -3
You'll have to experiment with the values.
I am trying to draw a histogram with broken x-axis. I learnt the basic solution from this post.
However, the x-axis of my histogram is based on strings, not number. It's like this:
set terminal pdf
set output "test-bar.pdf"
set boxwidth 1.0 absolute
set style fill solid 1 border 0
set datafile separator ','
set style data histograms
set xtics nomirror rotate by -45
set ylabel 'Normalized Overhead (%)'
set grid ytics
set yrange [0:10]
plot 'test-bar.csv' using 2:xtic(1) lc rgb "#1E90FF" title ''
And the data is listed like this:
expand , 8.63390441828
cut , 6.84657194596
sync , 6.03615235627
fold , 4.22117995557
nl , 3.54228486647
truncate , 2.66222961714
tr , 2.38357169059
stty , 2.28166797757
users , 2.04211869831
factor , 1.81517270821
tac , 1.790947574
uniq , 1.78799489138
mv , 1.75054704603
mktemp , 1.72228202368
dircolors , 1.6974169738
Right now the plot is in this way:
If I want to leverage the broken axis feature, say, insert the broken between stty and users, how can I do that?
Am I clear enough? Thanks.
Although you use xtic labels from your data file, the xtics are placed at integer x-values, starting at 0. Now, you cannot directly set arbitrary x-values when plotting histograms. You must use newhistogram at ... to shift the second part of the histogram further to the right:
split = 8
plot 'test-bar.csv' using 2:xtic(1) every ::0::(split-1) lt 1,\
newhistogram at split+1,\
'' using 2:xtic(1) every ::split lt 1
Drawing of the upper and lower borders as well as the broken axis signs is done as shown in the post you linked. A possible full script could be
set terminal pdf
set output "test-bar.pdf"
set boxwidth 0.5 absolute
set style fill solid 1 border 0
set datafile separator ','
set style data histograms
set style histogram rowstacked
set xtics nomirror rotate by -45
set ylabel 'Normalized Overhead (%)'
set grid ytics
set yrange [0:10]
unset key
set border 2+8
set linetype 1 lc rgb "#1E90FF"
split=8
dx = 0.125
dy = 0.03
do for [i=0:1] {
set arrow 1+i from graph 0,graph i to first split-dx,graph i lt -1 nohead
set arrow 3+i from first split+dx,graph i to graph 1,graph i lt -1 nohead
set arrow 5+i from first split-2*dx,graph i-dy to first split,graph i+dy lt -1 nohead
set arrow 7+i from first split,graph i-dy to split+2*dx,graph i+dy lt -1 nohead
}
plot 'test-bar.csv' using 2:xtic(1) every ::0::(split-1) lt 1,\
newhistogram at split+1,\
'' using 2:xtic(1) every ::split lt 1
Alternatively, if you don't add or stack more columns, you could use the boxes plotting style, which allows you to use a normal numerical axis.