python - 如何将 matplotlib 的 ggplot 风格与 agg 后端一起使用

标签 python matplotlib jenkins

我的问题如下:

我有一个通过 Jenkins 作业远程运行的脚本。 该脚本正在制作绘图并使用 plt.savefig()

保存它们

如果导入顶部没有以下行,我无法从 jenkins 运行我的脚本:

matplotlib.use('Agg')

当我添加这个时,我的绘图上就不再有 ggplot 样式:

这一行:

matplotlib.style.use('ggplot')

出现以下错误:

Traceback (most recent call last):
  File "plot.py", line 5, in <module>
    matplotlib.style.use('ggplot')
AttributeError: 'module' object has no attribute 'style'

请注意:

  • 当我在没有行 matplotlib.use('Agg')

  • 的情况下执行脚本时,这种样式在本地工作
  • 脚本在没有ggplot样式的jenkins上正常运行。

我如何才能在远程服务器上同时拥有两者?

(python 2.7.6,matplotlib 1.4.3)

最佳答案

style 是一个可以从 matplotlib.pyplot 导入的包,而不是直接从 matplotlib 导入。

所以,尝试一下:

import matplotlib.pyplot
matplotlib.pyplot.style.use('ggplot')

关于python - 如何将 matplotlib 的 ggplot 风格与 agg 后端一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32496432/

相关文章:

git - 在 OpenShift 构建之前运行 Grunt 构建

jenkins - 通过 GUI 删除 Jenkins 构建

python - 如何在 Matplotlib 中旋转花式箭头

python - Matplotlib tight_layout -- 删除多余的白色/空白空间

python - Matplotlib 日期作为刻度

Jenkins htmlpublisher 问题

python - 不难处理的元素 Selenium

python - 来自列表字典的 DataFrame,其中列值为键

python - 为数据库中现有条目生成 slug 字段数据

python - 如何使用新格式打印大括号