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
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
I am plotting a transparent surface using pseudofile '++' (gnuplot 5.2):
set isosample 100
set style fill transparent solid 0.65
splot [0:5][0:5] '++' u 1:2:(sin($1)*sin($2)) w pm3d
but it results in a plot with both lines around each tile of the surface.
I am not sure how to make these transparent as the tiles, or how to suppress them altogether. Using the noborder or any border option of set style fill does not seem to change the output at all.
EDIT: The problem is actually terminal dependent.
above plot is with the qt terminal using its built in export
png, jpg and gif have lines :
But if exported as vector graphics (svg or pdf), again the screen rendering will depend on the viewer used (okular no lines, acrobat reader 9 has them), with some renderers having no lines: check here how your browser behaves (firefox, chromium, epiphany on my linux box are all line-free)
Output of show pm3d:
pm3d style is explicit (draw pm3d surface according to style)
pm3d plotted at SURFACE
taking scans direction automatically
subsequent scans with different nb of pts are flushed from BEGIN
flushing triangles are not drawn
clipping: all 4 points of the quadrangle in x,y ranges
pm3d quadrangles will have no border
steps for bilinear interpolation: 1,1
quadrangle color according to averaged 4 corners
I am trying to plot two data series plotted in one graph (histogram) using gnuplot. One is Baseline data and other one is Optimized. The script looks like this currently.
n=50
max=0.07946462
min=0.0
reset
width=(max-min)/n #interval width
hist(x,width)=width*floor(x/width)+width/2.0 #function used to map a value
to the intervals
set term png #output terminal and file
set output "histogram.png"
set xrange [min:max]
set yrange [0:]
set style fill solid 0.5 #fillstyle
set termopt enhanced # turn on enhanced text mode
set xlabel "PowerDensity(mA/um2)"
set ylabel "Area(um2)"
set title 'Power Density Histogram'
plot 'power_density_oxili_sptp.txt' u (hist($2,width)):($1) smooth frequency
w boxes lc rgb"blue" title 'Baseline', 'power_density_oxili_sptp.txt' u
(hist($3,width)):($1) smooth frequency w boxes lc rgb"red" title 'Optimized'
The output of this will be as given
enter image description here
The problem here, I am not able to see baseline data (blue) completely,since it is hiding below the optimized data.Either I need to see both data or I need to plot histogram separately in the same graph.
Br
Sree
It looks like you want the two histograms to be transparent. For that you should set the transparent flag in your fillstyle (see help fillstyple):
set style fill transparent solid 0.5
In addition, you need to specify truecolor to get transparent areas from the standard png terminal (see help png):
set term png truecolor
Alternatively you can use the pngcairo terminal.
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...
I am generating mapped 3D plots using the following config file (XRANGE and YRANGE are set later)
#!/usr/bin/gnuplot
reset
set term postscript eps enhanced
set size square
set xlabel "X position"
set ylabel "Y position"
#Have a gradient of colors from blue (low) to red (high)
set pm3d map
set palette rgbformulae 22,13,-31
set xrange [0 : XRANGE]
set yrange [0 : YRANGE]
set style line 1 lw 1
unset key
set dgrid3d 45,45
set hidden3d
splot "data.data" u 1:2:3
The resulting image looks something like this
Note: I have converted to jpg so the quality is lower, and I have placed a border around the image.
A great deal of space is wasted above and below. This is not a problem until I embed the image into a LaTex document, at which point it will look like so (again, pdf document converted to jpg image)
The image on the right is also created with GnuPlot, but it is slightly larger (as is evident by looking at the border I have drawn around the top two images). The reason for this is because GnuPlot pads the 3D plot with top and bottom white space. How can I remove this without having to manually edit all 50+ plots I have?
There are two solutions to this, one is unreliable, the other is a hack.
Using GnuPlot, the margin settings can be used to specify distances from the appropriate margins. For example, setting lmargin 0 and bmargin 0 essentially pushes the axes off the page. Similar values can be assigned to the tmargin and rmargin to stretch the graph. Although this worked for 2D graphs, it did not work for 3D graphs (I suspect this has to do with the fact that I set the graph to be a square).
When graphs are set to be of square size, Gnuplot still calculates for the entire screen. The eps file can be manipulated directly to change this by looking for a line like so %%BoundingBox: 50 50 410 302 and changing 410 to something smaller. Alternatively, and this is what I did, you can run eps2eps in.eps out.eps and it will crop it for you. Just make sure in.eps is not the same file as out.eps or it won't work.
I also crop the Bounding Box afterwards, since I hate playing around with margins in gnuplot. I realized that somehow, eps2eps indeed does adjust the bounding box, but it also transforms text (labels etc) into pixel-graphic?!
I usually use "epstool" which conserves text as text when croping the bb, the command I use is:
epstool --copy --bbox in.eps out.eps
Use the <scale> argument in set view, this will magnify the plot without changing text size or title position.
In your case, because you use the map view, you need:
set view 180,0,1.5
where 180,0 is equivalent to map view and 1.5 is the scaling factor.