I decided to migrate to the latest version of gnuplot from 4.4 to 4.6
I am having issue with the x label disappearing with version 4.6 but being there with version 4.4.
here is a stripped down version of my script.
set key outside
set title "MY TITLE"
set timefmt "%m/%d/%Y-%H:%M:%S"
set format x "%m/%d %H:%M"
set xdata time
set ylabel "Y LABEL"
set xlabel "Time"
set grid
set xtics rotate by 90 offset 0,-5
set terminal pngcairo size 1000,500 font ",9"
set xtics font ",8.0"
set ytics font ",8.0"
set output 'test.png'
plot '-' using 1:2 with linespoints ti "legend"
01/01/2013-00:15 186557
01/01/2013-01:15 254654
01/01/2013-04:00 180146
01/01/2013-06:15 191059
e
set key inside
I've identified the issue to this line
set xtics rotate by 90 offset 0,-5
Because my label is too long the offset makes it go away
if you remove the offset to
set xtics rotate by 90
Not the label show but in the middle of the chart.
Version 4.4 used to compress the chart to leave room for the label.
I guess my knowledge to gnuplot is limited.
Anyone has an idea?
thanks
UPDATED ANSWER, courtesy of Ethan Merritt
A better way to do this is to change the justification of the labels to being right justified (rather than the default centered).
set xtics rotate by 90 right
This correctly calculates the margin without needing to hardcode a margin size
The label placement here seems a little flaky to me. I think there might be a bug which I'll probably report. One workaround is to explicitly set the location of the "x-axis" via:
set bmargin at screen 0.2
The reason it seems flakey is because with set bmargin at screen 0.2, the xtic labels clearly extend higher than the position of the xlabel. However, if you comment that line out, all of a sudden they don't extend higher than the position of the xlabel.
Here are the plots with and without that line:
Perhaps cairo/pango cut out labels where any portion of the label extends past the visible "canvas" area?
As a side note, the plot also seems to be roughly correct if I use the postscript terminal...
Related
I have a gnuplot SVG terminal. One issue that I'm facing when I output the files and import to powerpoint is that there is a lot of blank space especially at the Top, even though I mention that margin is 0.
Below is the example and the screen shot that shows blankspace when imported in powerpoint.
My question is how to remove blank space so I dont have to trimp or crop using another tool.
reset session
set terminal svg size 600,600 enhanced font 'Verdana,10'
set output 'output.svg'
set view 50,10
set isosample 40
set xlabel "x"
set ylabel "y"
set zlabel "f(x,y)" rotate
set pm3d noborder
set palette rgb 33,13,10
unset colorbox
set lmargin 0
set rmargin 0
set bmargin 0
set tmargin 0
set log cb
set cbrange [0.1 : *]
splot [x=-2:2] [y=-1:3] (1-x)**2+100*(y-x**2)**2 with pm3d notitle
set output
The "set margin" commands in the form you show them are designed to describe the space between the x and y borders of a 2D plot and the edges of the page. Their effect on a 3D plot rotated so that the x/y plot borders are not parallel to the page is non-obvious.
I suggest using instead a different form of the bmargin command that positions the bottom of the 3D view box at a specific screen location, followed by a scaling command to increase the vertical size by a factor of, say 1.6 or so. The vertical scale operates symmetrically above and below the center of the 3D view box. My preference would be to also get rid of the empty space inside the view box by repositioning the base plane to z=0. The additional command and their result is shown here.
set bmargin at screen 0.4 # reposition entire plot upwards
set view 50, 10, 1.0, 1.6 # increase default vertical scale by 1.6
set xyplane at 0 # remove space between base plane and bottom of surface
replot
If the same label (in a font different than that of the plot) is used in a series of plots, the line spacing in the first of them seems to follow the plot's font, i.e., it's considerably larger or smaller than in the remaining plots:
Setting the key spacing has no influence on this behavior. And this doesn't happen when label and plot fonts are the same.
How can that be avoided?
Here's a minimal code that produces the plots above:
set terminal png size 200,200
set label "1st line\n2nd line" font "monospace, 8"
set output "1.png"
plot x
set output "2.png"
plot x
Gnuplot 5.2 patchlevel 6, under Linux, was used.
This is indeed a strange behaviour. To me this looks like an initialization bug.
If I start the code from the gnuplot command line, it happens only the first time. If you plot again, the line spacing seems to be the correct one.
So, how can this be avoided? Plot it twice! I agree, this is not a really satisfying solution, there must be better ones.
Code:
reset session
set terminal png size 200,200
set label 1 "1st line\n2nd line" font "monospace, 8"
set output "1.png"
plot x
set output "1.png"
plot x
set output "2.png"
plot x
set output
Addition:
Another possibility to workaround might be the following. Set monospace,8 as default for the terminal. But then adjust the font of all other labels like xtics, xlabel, ytics, ylabel, key, ...
Code:
reset session
set terminal png size 200,200 font "monospace, 8"
set label 1 "1st line\n2nd line"
set xtics font "Arial, 12"
set ytics font "Arial, 12"
set key font "Arial, 12"
set output "1.png"
plot x
set output "2.png"
plot x
set output
Result:
As Ethan pointed out in comments:
It is a bug that is specific to the libgd-based terminals (png jpeg gif). You can avoid it by choosing set term pngcairo instead.
The bug has been reported and is already
Fixed in 5.2.8, which will be released by the end the month [Nov 2019].
I am trying to plot a function of two variables represented in tabular form. I would like to label my color bar while representing this as a heatmap. No matter how much I rescale, no luck, and I don't even see the colorbar label appearing. Here is my gnuplot script:
set title "Flux in core vs radius and height"
set view map
set cblabel "Neutron flux (cm^-2 s^-1)"
set xlabel "Radius (cm)"
set ylabel "Axial distance from center (cm)"
splot "flux.out" using 1:2:3 with image
And the result looks like this, lacking a colorbar label:
The cblabel is printed outside the picture. You can manually adjust the margins to make some space for the label:
set lmargin at screen 0.1
set rmargin at screen 0.7
I used at screen because else the picture would be cropped again. And I also set lmargin because else in my test the ylabel would not fit on the page.
Tested with Gnuplot 4.6.
I am making a video for my simulation, where each each frame is a picture of the simulation, and a graph. I'm making the graph with gnuplot, and I first run the simulation to determine the x and y ranges to use and then hardcode the range into the plot script. It works okay, but the plot does not use up the entire surface, there is a ton of white space, and the plot is only about 1/4 of the total area. Is there a way to make the plot expand closer to the edges of the boundary, or a way to control the plot placement?
Script:
set term postscript eps color enhanced "Helvetica" 36
set output 'image.eps'
set size ratio 0.8
set logscale x
set xlabel 'Time(Arb. Units)'
set xrange [10:100000]
set yrange [0:1.6]
set y2range [0:0.5]
set ylabel 'Absorption(%)'
set y2label 'Emission'
set format x '%.0e'
set xtics 10, 100, 100000
set key noautotitles
plot 'absorption.dat' axes x1y1 w lines lt 3 lw 5, 'emission.dat' axes x1y2 w lines lt 1 lw 5
Here is what comes out:
I set a grey background so you can see what space is being wasted.
Edit: I've also tried the png terminal, but that seems to make the problem even worse. The plot is shrunk even further. I replaced the top two lines of the script with:
set term png font Helvetica 36
set output 'image.png'
Then this is what comes out:
There are several things involved in the computation of the plot size:
Different terminals have different default canvas sizes. If the defaults don't fit your needs, change the size set terminal ... size ...
The canvas has a fixed aspect ratio (given by the terminals size settings) and you impose an additional constraint with set size ratio... which affects only the plot but not the canvas size. So, if you need this size ratio you must adapt the plot canvas to it.
A third parameter are the margins. Since gnuplot don't exactly know how the labels will be rendered by the terminal, the margins cannot be exact. You can set margins manually with set bmargin ... (for the bottom margin) and equivalently for the other margins.
I would suggest to use a terminal that accept the crop flag
e.g. png, gif, jpeg but also epscairo
I'm trying to model a certain progress through some environment. The x axis would represent the location (based on x coordinate) in the environment.
In order to make this clear, I'd like an image of the environment (based on a .png) on the x axis (the environment is rather wide and not that high, so it should look good) of my plot, basically as an xtics/x-axis label.
Do you have any suggestions on how to approach this?
Thanks in advance!
You can either plot both the image and the data in one plot command, or with multiplot. The first variant is easier, but the image is inside the plot, the other is a bit more complicated, but allows arbitrary positioning of the "axis image".
The dummy image "gradient.png" for the axis is
One plot command:
set yrange[0:1]
set xrange[0:1]
plot 'gradient.png' binary filetype=png dx=0.0015 dy=0.002 with rgbimage t '',\
x**2
The result is:
Using multiplot
set yrange[0:1]
set xrange[0:1]
set lmargin at screen 0.1
set rmargin at screen 0.98
set tmargin at screen 0.98
set bmargin at screen 0.2
set xtics offset 0,-1.5
set xlabel 'xlabel' offset 0,-1.5
set ylabel 'ylabel'
set multiplot
plot x**2
set tmargin at screen 0.2
set bmargin at screen 0.15
unset border
unset tics
unset xlabel
unset ylabel
unset key
set autoscale xy
plot 'gradient.png' binary filetype=png with rgbimage
unset multiplot
As you can see, this requires a bit more effort. To explain the details:
You must set explicit margins so that the axis image can be placed exactly below the main plot.
Before plotting the axis image, you must remove tics, labels, reset ranges to autoscale etc. (Therefore you must also set fixed lmargin and rmargin).
To plot the image itself, use the plotting style with rgbimage.
You must fine-tune the xtics and xlabel offset, as well as the marings.
The resulting image is: