4

I want to have blank background in my figure, however, it seems that the for some reason the default is not. Here is an example:

import matplotlib.pyplot as plt
x=[1,2]
y=[3,4]
plt.plot(x,y)

This gives me the following figure:

enter image description here

Why do I get this gridded grey background by default? How would one change the default? And perhaps also how would that differ from setting it only for one figure without changing defaults? Thanks

Edit: Apparently, this happened because I imported the seaborn module, as the answer suggested. But why does this behavior occur? So if I want to use both seaborn and matplotlib in one script, I need to keep setting the default background?

1

1 Answer 1

8

What you show in the question isn't actually the matplotlib default style. You may get this because you may have imported some other modules.

To get back the default style use

plt.rcParams.update(plt.rcParamsDefault)

When e.g. seaborn is imported it sets its own style. This is a very greedy behaviour, but you can of course set another style afterwards

%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
plt.style.use('seaborn-paper')

You may want to look at the style reference.

This question may be of interest when no other style is desired. The idea is, to only load the API, without the styles from seaborn

import seaborn.apionly as sns
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @ImportanceOfBeingErnest, you're right on the money. I imported the seaborn module and this caused it. I also edited the question to get some insight about why this is happening.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.