gnuplot svg blank space when output to PowerPoint - svg

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

Related

gnuplot multiplot images in column

I'm trying to use multiplot to stack two image plots on top of one another, in a column. When I try to test this with x11 terminal, the images are produced separately, only one visible at a time. When I use the epslatex terminal, which is what I want, then the text is drawn correctly within the LaTeX document, but the EPS portion of the plot is produced as two separate pages, resulting in a figure that is missing a lower half.
Here's the multiplot section of my script:
set multiplot 2,1
set cbrange [-0.4:0.4]
set cbtics -0.4,0.2,0.4
unset xlabel
set tmargin at screen 0.95
set bmargin at screen 0.60
plot data u 1:2:3 with image notitle
set cbrange [-0.1:0.1]
set cbtics -0.1,0.05,0.1
set xlabel "$x$"
set tmargin at screen 0.50
set bmargin at screen 0.15
plot data u 1:2:3 with image notitle
unset multiplot
unset output
What results in the document is this:
I have tried enlarging the vertical size of the plotting area(per this question), but what this does is increase size of each page in the EPS file. To be clear, the product of plotting with epslatex is an EPS file containing two pages, the first with the first plot at the position that I want (near the top), and the second with the second plot at the position that I want (near the bottom).
This normally happens when you are not in multiplot mode. For me, set multiplot 2,1 gives an error message "only valid in the context of an auto-layout command". The command set multiplot layout 2,1 works with Gnuplot 5.0 and 4.6.
As a side note: This behavior can be used to produce animated gifs with set terminal gif animate, each plot command creates a new frame.

Gnuplot cblabel not appearing

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.

Gnuplot Expand Plot to Fill Area

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

gnuplot - no space between graph and png image edge

How to create a .png image in gnuplot to see no spaces between graph itself and image edges.
I use
set terminal pngcairo size 800,600 enhanced
I want exactly 800x600 image. And want all 0X axis correspond to [0..800] interval, and all 0Y correspond to [0..600] interval.
It looks like you want to set the margins to 0. Here is an example script:
set terminal pngcairo size 800,600 enhanced
set output 'output.png'
set lmargin 0
set rmargin 0
set tmargin 0
set bmargin 0
#unset tics
plot sin(x) # notitle
This way the plot will fill the canvas exactly. You can type help set margin in gnuplot for details. (Uncomment the comments in my example if you want a slightly cleaner plot.)

How to make plots larger in GnuPlot

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.

Resources