Reputation: 277
This is my code:
d1 = Gnuplot.Data(x1,y1, with_="lines lt rgb 'red'", title="1")
d2 = Gnuplot.Data(x2,y2, with_="lines lt rgb 'red'", title="2")
d3 = Gnuplot.Data(x3,y3, with_="lines lt rgb 'red'", title="3")
g.title("aaa")
g('set size 1,0.75')
g('set grid')
g('set term x11 2')
g('set logscale x')
g('set xtics 1,2,110')
g('set xrange [1:110]')
g.plot(d1,d2,d3)
g.hardcopy("aaa.png", terminal='png')
Both in the temporary plot of gnuplot.py and in the hardcopy, I have a big white strip in the upper part due to the 'set size 1,0.75'. Is it possible to avoid this and to have a figure exactly large as the plot?
Thanks
Upvotes: 2
Views: 1512
Reputation: 48440
Thats, what the command set size
is for: Change the plot size relative to the total canvas/image size. In order to change the image size, you must use the size
parameter of the set terminal
command. Unfortunately, that is not supported by some terminals which are defined in termdefs.py
of gnuplot-py. As the comment in termdefs.py
says:
"""Terminal definition file.
This module describes the options available to gnuplot's various terminals. For the moment, it only supports a few terminals, but the infrastructure is here to add others as they are needed. ...
The svg
terminal supports the size
parameter:
import Gnuplot
from numpy import *
x1 = arange(1,10)
y1 = arange(1,10)
d1 = Gnuplot.Data(x1,y1, with_="lines lt rgb 'red'", title="1")
g = Gnuplot.Gnuplot()
g.title("aaa")
g('set grid')
g('set logscale x')
g('set xtics 1,2,110')
g.plot(d1)
g.hardcopy("aaa.svg", terminal='svg', size=[800,400])
The most flexible way is to pass the raw terminal definition string to gnuplot. Then, the line g.hardcopy...
becomes:
g('set terminal pngcairo size 800,400')
g.set_string('output', 'aaa.png')
g.refresh()
g.set_string('output')
That allows you also to use the better pngcairo
terminal instead of the png
terminal.
Upvotes: 2