这是我的代码:
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')
在 gnuplot.py 的临时图中和硬拷贝中,由于“设置大小 1,0.75”,我在上部有一个大的白色 strip 。 是否可以避免这种情况并有一个与绘图完全一样大的图形?
谢谢
最佳答案
这就是命令set size
的用途:更改相对于 Canvas /图像总大小的绘图大小。要更改图像大小,必须使用 setterminal
命令的 size
参数。不幸的是,gnuplot-py 的 termdefs.py 中定义的某些终端不支持这一点。正如 termdefs.py
中的注释所述:
"""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. ...
svg
终端支持 size
参数:
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])
最灵活的方法是将原始终端定义字符串传递给 gnuplot。然后,行 g.hardcopy...
变为:
g('set terminal pngcairo size 800,400')
g.set_string('output', 'aaa.png')
g.refresh()
g.set_string('output')
这还允许您使用更好的 pngcairo
终端而不是 png
终端。
关于python - gnuplot.py 图的硬拷贝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22069083/