您设置初始化大小:
fig2 = matplotlib.pyplot.figure(figsize=(8.0, 5.0)) # in inches!
编辑:
如果问题是与x轴蜱 - 你可以在 “手动” 进行设置:
fig2.add_subplot(111).set_xticks(arange(1,3,0.5)) # You can actually compute the interval You need - and substitute here
等等与您的情节的其他方面。你可以配置全部。这里有一个例子:
from numpy import arange
import matplotlib
# import matplotlib as mpl
import matplotlib.pyplot
# import matplotlib.pyplot as plt
x1 = [1,2,3]
y1 = [4,5,6]
x2 = [1,2,3]
y2 = [5,5,5]
# initialization
fig2 = matplotlib.pyplot.figure(figsize=(8.0, 5.0)) # The size of the figure is specified as (width, height) in inches
# lines:
l1 = fig2.add_subplot(111).plot(x1,y1, label=r"Text $formula$", "r-", lw=2)
l2 = fig2.add_subplot(111).plot(x2,y2, label=r"$legend2$" ,"g--", lw=3)
fig2.add_subplot(111).legend((l1,l2), loc=0)
# axes:
fig2.add_subplot(111).grid(True)
fig2.add_subplot(111).set_xticks(arange(1,3,0.5))
fig2.add_subplot(111).axis(xmin=3, xmax=6) # there're also ymin, ymax
fig2.add_subplot(111).axis([0,4,3,6]) # all!
fig2.add_subplot(111).set_xlim([0,4])
fig2.add_subplot(111).set_ylim([3,6])
# labels:
fig2.add_subplot(111).set_xlabel(r"x $2^2$", fontsize=15, color = "r")
fig2.add_subplot(111).set_ylabel(r"y $2^2$")
fig2.add_subplot(111).set_title(r"title $6^4$")
fig2.add_subplot(111).text(2, 5.5, r"an equation: $E=mc^2$", fontsize=15, color = "y")
fig2.add_subplot(111).text(3, 2, unicode('f\374r', 'latin-1'))
# saving:
fig2.savefig("fig2.png")
所以 - 你想要什么配置?
感谢您的及时响应。但是,这并不能解决问题。保存到文件的图像是在调用'pylab.show()'时显示的图像。对于我正在绘制的数据,我需要(手动)最大化窗口,以便在标签之间提供足够的间距。几乎看起来,在这个场景后面,'pylab.savefig()'正在做一个'pylab.show()',然后对** DEFAULT **大小窗口进行屏幕截图并将其保存到文件中。我需要保存窗口显示为** MAXIMIZED **时显示的图像** – 2012-04-06 10:07:44
为什么不定制它所有的非GUI方式?我从来没有听说过可以让Python知道你已经在pylab.show()中完成了。 – Adobe 2012-04-06 10:27:45
我不确定我是否理解您的最新评论。我的意思是(如果你误解了我的评论),是你提出的解决方案,仍然会导致图像被保存到磁盘上,但仍然有所有X轴标签“皱在一起”并且不合格。我只是指出保存到文件的图像与调用“pylab.show()”时创建的图像完全相同。只有当我最大化GUI窗口时,才能正确读取所有X轴标签。在我的脚本中,我生成了数百个图像,因此手动最大化每个窗口并保存是不切实际的。 – 2012-04-06 10:46:53