I have a histogram plot where the bars are simply too high that they overlap the box at the top right that displays information about each bar (what do you call this box?)
Currently it looks like this:
I'm been tring to change the size (height) of the canvas so that it is taller with set size but I couldn't get it to work. I then used yrange but I don't want to specify more range to solve this problem. I want it so that the inner canvas is more square and not rectangular (more height) without changing the range. How do I do this?
set term png
set output 'output.png'
red = "#FF0000";
green = "#00FF00";
blue = "#0000FF";
skyblue = "#87CEEB";
purple = "#4B0082";
set ylabel "Time (s)"
set xlabel "CPU"
set style data histogram
set style histogram cluster
set style fill solid
set boxwidth 0.9
set grid ytics
set xtics rotate
set title "Compiled with gcc/g++"
plot "processor.dat" using 2:xtic(1) title "-O1" linecolor rgb red, \
'' using 3 title "-O2" linecolor rgb blue, \
'' using 4 title "-O3" linecolor rgb green, \
'' using 5 title "-Os" linecolor rgb skyblue, \
'' using 6 title "-Ofast" linecolor rgb purple
The "box" is called "key". In the gnuplot command line, help set key explains its options. You can move it to the empty left upper corner with
set key left
To increase the height of the picture I would change the overall size of the png like this:
set terminal png size 640,640
On my system, your command set term png defaults to set terminal png size 640,480.
To make the plot area an exact square, the following command is used:
set size ratio 1
This is the result with some fake data:
Related
I need to make a 2d plot and a 3d plot, which I want to save as .tex files, respectively labo2-mag/latex/position-x-y-over-time.tex and labo2-mag/latex/position-3d.tex. Is there anything wrong with my script ?
# General settings
set tics font ", 14"
set tmargin at screen 0.7
set key at screen 0.3, 0.8 font ",14" spacing 1.3 samplen 0.8 box opaque
# set key outside font ",14" spacing 1.3 box opaque
# Send the border to the background
set border lw 0.1 back
set xlabel '$t$ [s?]' offset 1.7;
set ylabel '$Position$ [m?]' offset -1;
# Plot once 'in the air'
# set terminal unknown
plot "labo2-mag/data/output.out" using 1:2 with points pointtype 6 lc rgb "red" title '$x(t)$', \
"" using 1:3 with points pointtype 8 lc rgb "green" title '$y(t)$', \
"" using 1:4 with points pointtype 6 lc rgb "blue" title '$z(t)$'
# pause 70
# reread
set terminal cairolatex pdf size 10cm, 10cm
set out 'labo2-mag/latex/position-x-y-over-time.tex'
MAX_Y=GPVAL_Y_MAX
MIN_Y=GPVAL_Y_MIN
MAX_X=GPVAL_X_MAX
MIN_X=GPVAL_X_MIN
set xrange [MIN_X-(MAX_X-MIN_X)*0.1:MAX_X+(MAX_X-MIN_X)*0.01]
set yrange [MIN_Y-(MAX_Y-MIN_Y)*0.05:MAX_Y+(MAX_Y-MIN_Y)*0.05]
replot
# reset terminal
splot "labo2-mag/data/output.out" using 2:3:4 with points pointtype 6 lc rgb "red" title '$pos(t)$'
set terminal cairolatex pdf size 10cm, 10cm
set out 'labo2-mag/latex/position-3d.tex'
replot
Your splot command is issued while the first terminal is still active and writing to the first output file. You need to change the terminal and output before doing a new plot. The minimum would be to issue unset output after each of your replot statements.
You might want or need to also set a new intermediate terminal type together with the unset output. I don't understand the "in the air" comment in the script. Do you mean you don't actually want to plot it? You want to view it interactively before plotting to a file? Otherwise maybe set terminal dumb? If it is relevant, please clarify.
my gnuplot script plot bar graphs in the following 2D format:
using the following sctipt:
set term pngcairo size 800,600
set termoption noenhanced
set title "$file_name" font "Century,22" textcolor "#b8860b"
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
plot '<cat' using 2:xtic(1) with boxes
In order to add values above the bars, I've tried to modify it to
plot '<cat' using 0:2:xtic(1) with boxes, '' u 0:2:2 w labels offset 0,1
but the values were not added to the bars, with the following warning
"/dev/fd/63" line 17: warning: Skipping data file with no valid points
I can only test for Windows, but I assume cat under Linux is the equivalent for type under Windows.
So, what is your filename? I would say your filename is simply missing. Check help piped-data.
Something like the following should work:
plot '<cat myDataFile.dat' using 0:2:xtic(1) with boxes, '' u 0:2:2 w labels offset 0,1
But then, what is the difference to using directly the filename?
plot 'myDataFile.dat' using 0:2:xtic(1) with boxes, '' u 0:2:2 w labels offset 0,1
I want to put the Y values over the top of bars of the histogram for the graph below:
`
set style data histogram
#clustered
#set terminal wxt enhanced persist
set term post eps enhanced "Times-Roman, 14"
set output 'avg_waste.bmp'
set boxwidth 1.3
set grid
set auto y
set auto x
set style histogram clustered gap 1 title offset 1,0.25
set ylabel "\nAverage Resource Wastage\n\n\n" font "Times-Roman,25"
set xlabel "\nWorkflows\n" font "Times-Roman,25"
#set style fill solid noborder
set style fill pattern border -1
set key at graph 0.2, 0.9
set key spacing 2 font "Times-Roman,18"
set xtics font ", 25"
set ytics font ", 25"
plot for [COL=2:3] 'avg_waste' using COL:xticlabels(1) title columnheader fs pattern 2 `
when I try to use labels, gnuplot gives the error Not enough columns for this style
My data file is
#WASTAGE
CRCH HEFT
Cybershake 20.89 22.5785714286
LIGO 187.3228571429 199.5134285714
SIPHT 205.7514285714 210.3685714286
Montage 12.1485714286 12.7942857143
One possibility would be to place those labels manually as for example:
reset
fontSpec(s) = sprintf("Times-Roman, %d", s)
set term post eps enhanced fontSpec(16)
set output 'avg_waste.eps'
set grid
set auto y
set auto x
ticsFont=fontSpec(16)
set xtics font ticsFont
set ytics font ticsFont
set ylabel "Average Resource Wastage" font fontSpec(25) offset char -1,0
set xlabel "Workflows" font fontSpec(25) offset 0,char -1
set style fill pattern border -1
set style data histograms
set boxwidth 1.0
set style histogram clustered gap 1
keyFont=fontSpec(18)
set key spacing 2 font keyFont
#using directly 'set key spacing 2 font fontSpec(18)' doesn't seem to work...
set key at graph 0.25, 0.9
fn(v) = sprintf("%.1f", v)
plot \
for [COL=2:3] 'avg_waste' using COL:xticlabels(1) title columnheader fs pattern 2, \
'avg_waste' u ($0-1-1./6):2:(fn($2)) w labels font fontSpec(14) offset char 0,0.5 t '' , \
'avg_waste' u ($0-1+1./6):3:(fn($3)) w labels font fontSpec(14) offset char 0,0.5 t ''
Also, since you seem to want to use the titles taken from columnheaders, the script above assumes that the input data is of the form:
WASTAGE CRCH HEFT
Cybershake 20.89 22.5785714286
LIGO 187.3228571429 199.5134285714
SIPHT 205.7514285714 210.3685714286
Montage 12.1485714286 12.7942857143
i.e., the first line is not commented out.
This then produces:
EDIT:
As for the using specification ($0-1-1./6):2:(fn($2)), it's based on the fact that the individual "block" of bars are centered at integer coordinates 0,1,2, and 3. Now, with two blocks per group, the width of each block is 0.3 (2 blocks between the centers of each group + one empty one for the space). The column 0, $0, contains the 0-based index of a particular line in the data file so for example for the "Cybershake" line, it is equal to 1, thus the syntax ($0-1-1./6):2:(fn($2)) then tells Gnuplot to place a label generated by the function fn at coordinates -1./6,$2, i.e., on top of the left bar in the "Cybershake" group. Here, fn is used just as a "macro" to format an input floating point number via the sprintf function.
So, I am playing around with gnuplot, and it somehow behaves weird. here is the full code:
reset
#set terminal cairolatex pdf input
#set output 'test.tex'
set terminal wxt
poisson(n) = nexp**n/int(n)!*exp(-nexp)
nexp = 3
ax = nexp
ay = 1
bw = 0.2
set xrange[-0.5:12.5]
set samples 13
#set style data boxes
set boxwidth bw absolute
set style fill transparent solid 0.5 border
set xtics 1
set xlabel '$n$'
set ylabel 'Probabiltity of finding $n$ photons'
set key off
plot '+' using (ax+bw/2):(ay) with boxes lc rgb"green" title 'Fock state with $n = 3$',\
'+' using ($0-bw/2):(poisson($0)) with boxes lc rgb"blue" title 'Coherent state with $\langle n \rangle = 3$'
This is the output I get:
For some reason the green box is not transparent in the plot, but transparent in the key. Anyone knows why or how to solve it?
Thanks a lot for any tips.
You generate 13 samples and plot 13 boxes at the sample place. Of course you don't see the transparency anymore. Change the first part of your plot command to draw a single box only:
plot '+' using (ax+bw/2):($0 == 0 ? ay : 1/0) with boxes lc rgb "green"
I'm trying to put two figures side by side using gnuplot with multiplot.
I want the resulting image to be rectangular so I use set size 2, 1. I also set the set multiplot layout 1, 2 option. However, the resulting image only uses the left part of the available space. Any help will be appreciated.
Thanks
Ahmet
Here is the resulting image
http://tinypic.com/r/33mlz04/6
And below is the gnuplot commands I'm using.
set terminal postscript eps color enhanced
set output 'figure.eps';
set size 2,1;
set multiplot layout 1, 2 ;
set title "Figure 1";
plot "data1.txt"
set title "Figure 1";
plot "data2.txt"
unset multiplot
Although I'm not very sure, with some trial and error I have solved it
set terminal postscript eps color enhanced
set output 'eps/image.eps';
set size 1,0.5;
set multiplot layout 1, 2 ;
set title "Figure 1";
set size 0.5,0.5;
plot "data/data1.txt"
set title "Figure 1";
set size 0.5,0.5;
plot "data/data2.txt"
unset multiplot
Try something like:
set terminal postscript eps color enhanced size 10,5
set output 'figure.eps';
set multiplot layout 1, 2 ;
set title "Figure 1";
plot "data1.txt"
set title "Figure 1";
plot "data2.txt"
unset multiplot
When you set the size on the terminal specification line, that determines the actual size of the plot canvas (in inches in this case). When you use set size on a separate line, that sets the size of the plot in relative units of the canvas size. This is different in older versions of gnuplot. For perhaps a better explanation, try help set size in gnuplot.
For even more control over the size/position of the plot, you can use set origin in conjuction with set size to change the placement and size of each plot. Finally, the most control can be achieved with set lmargin at <place> (and set rmargin ...) and so-on for tmargin and bmargin where the "lrtb" stand for left, right, top and bottom respectively.
So, to get a plot to fill all of the available space (left to right), you could:
set multiplot
set lmargin at 0
set rmargin at .5
plot sin(x)
set lmargin at .5
set rmargin at 1
plot cos(x)
unset multiplot
However, this is (usually) overkill. Usually gnuplot tries to make the margins big enough for your labels and such, but setting the margin explicitly disables that. I would suggest you go with the solution by andyras.
if you are having problems using this method for more than 2 figures add 'set origin 0,0' after 'set size 0.5,0.5'.
For example, for three figures :
set terminal postscript eps color enhanced
set output 'eps/image.eps';
set size 1.5,0.5;
set multiplot layout 1, 3 ;
set title "Figure 1";
set size 0.5,0.5;
set origin 0,0
plot "data/data1.txt"
set title "Figure 2";
set size 0.5,0.5;
set origin 0,0
plot "data/data3.txt"
set title "Figure 3";
set size 0.5,0.5;
set origin 0,0
plot "data/data3.txt"
unset multiplot