YOBA
YOBA

Reputation: 2807

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. This script is making plots and saving them with plt.savefig()

Without the following line on the top of my imports, I can not run my scripts from jenkins:

matplotlib.use('Agg')

The moment I added this, I could no longer have the ggplot style on my plots:

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:

How can I have both on a remote server?

(python 2.7.6, matplotlib 1.4.3)

Upvotes: 1

Views: 960

Answers (1)

tmdavison
tmdavison

Reputation: 69183

style is a package that can be imported from matplotlib.pyplot, not directly from matplotlib.

So, try:

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

Upvotes: 2

Related Questions