[英]using matplotlib giving me the following warning: "UserWarning: tight_layout:
Try to do a graph using python matplotlib: but keep getting the following waring message: 尝试使用python matplotlib做一个图:但继续得到以下waring消息:
"UserWaring: tight_layout: falling back to Agg renderer warnings.warn("tight_layout: falling back to Agg renderer")
My code is below: 我的代码如下:
plt.legend(loc='upper left',prop = {'size':7},bbox_to_anchor=(1,1))
plt.tight_layout(pad=7)
plt.xlabel ('Build')
plt.ylabel ('Time/Sec')
plt.title ('Performance Test')
plt.grid()
plt.show()
Are you using MacOSX? 你在使用MacOSX吗? It seems to be a known and open issue
这似乎是一个众所周知的问题
https://github.com/matplotlib/matplotlib/issues/1852 https://github.com/matplotlib/matplotlib/issues/1852
I will suggest to reorganize the code such that you will use Figure instead of pyplot. 我建议重新组织代码,以便使用Figure而不是pyplot。 You can get the Figure from plt.figure() method.
您可以从plt.figure()方法获取图。 Then, on the Figure instance call set_tight_layout(True).
然后,在Figure实例上调用set_tight_layout(True)。 Try this example code:
试试这个示例代码:
import matplotlib
matplotlib.use('pdf')
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
fig.set_tight_layout(True)
fig.savefig('asd.pdf') # No warning now
As a side note, have a look at matplotlib documentation 作为旁注,请看一下matplotlib文档
tight_layout() can take keyword arguments of pad, w_pad and h_pad.
tight_layout()可以获取pad,w_pad和h_pad的关键字参数。 These control the extra padding around the figure border and between subplots.
它们控制图形边界周围和子图之间的额外填充。 The pads are specified in fraction of fontsize.
焊盘以字体大小的分数指定。
http://matplotlib.org/users/tight_layout_guide.html http://matplotlib.org/users/tight_layout_guide.html
This suggest that your code 这表明你的代码
plt.tight_layout(pad=7)
is wrong, as the value of pad should be between 0 and 1. 是错误的,因为pad的值应该在0和1之间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.