[英]How to use ggplot style of matplotlib with agg backend
My problem is as follows: 我的问题如下:
I have a script running remotely via a Jenkins job. 我有一个通过Jenkins作业远程运行的脚本。 This script is making plots and saving them with
plt.savefig()
该脚本正在绘制图并使用
plt.savefig()
保存它们
Without the following line on the top of my imports, I can not run my scripts from jenkins: 如果在导入顶部没有以下行,则无法从jenkins运行脚本:
matplotlib.use('Agg')
The moment I added this, I could no longer have the ggplot style on my plots: 添加此刻后,我的绘图将不再具有ggplot样式:
This line: 这行:
matplotlib.style.use('ggplot')
is giving the following error: 正在给出以下错误:
Traceback (most recent call last):
File "plot.py", line 5, in <module>
matplotlib.style.use('ggplot')
AttributeError: 'module' object has no attribute 'style'
NOTE that: 注意:
this style was working locally when I was executing the script without the line matplotlib.use('Agg')
当我执行没有行
matplotlib.use('Agg')
的脚本时,这种样式在本地工作
And the script runs normally on jenkins without the ggplot style. 而且该脚本可以在没有ggplot样式的詹金斯上正常运行。
How can I have both on a remote server? 如何在远程服务器上同时使用它们?
(python 2.7.6, matplotlib 1.4.3) (python 2.7.6,matplotlib 1.4.3)
style
is a package that can be imported from matplotlib.pyplot
, not directly from matplotlib
. style
是可以从matplotlib.pyplot
导入的包,而不是直接从matplotlib
导入的包。
So, try: 因此,请尝试:
import matplotlib.pyplot
matplotlib.pyplot.style.use('ggplot')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.