How can I use seaborn without changing the matplotlib defaults? - python

I am trying to use seaborn, because of its distplot function. But I prefer the default matplotlib settings. When I import seaborn, it changes automatically the appearance of my figure.
How can I use seaborn functions without changing the look of the plots?

Version 0.8 (july 2017) changed this behaviour. From https://seaborn.pydata.org/whatsnew.html#v0-8-0-july-2017:
The default (seaborn) style is no longer applied when seaborn is
imported. It is now necessary to explicitly call set() or one or more
of set_style(), set_context(), and set_palette(). Correspondingly, the
seaborn.apionly module has been deprecated.
For older versions, Import seaborn like this:
import seaborn.apionly as sns
and then you should be able to use sns.distplot but maintain the default matplotlib styling + your personal rc configuration.

According to documentation reset_orig restore all RC params to original settings:
import seaborn as sns
# reset RC params to original
sns.reset_orig()

Related

Show p-value in seaborn.jointplot

I'm having a hard time finding out how to show "p" and "pearsonr" values in seaborn plots (as well as just get them), as it seems latest versions no longer show them as default.
Code i'm using:
import seaborn as sns
sns.jointplot('A','A',tech_rets,kind='reg',color='seagreen')
As you can predict, p and pearsonr values are expected to be 0 and 1, respectively.
I've been through several posts here in stackoverflow, which answers sugest using a jointgrid method, such as:
import seaborn as sns
import scipy as stats
sns.jointplot('A','A',tech_rets,kind='reg',color='seagreen').annotate(stats.pearsonr)
But then, it seems that "stats.pearsonr" is outdated.
Thank you in advance!

Why am I getting UserWarning: Matplotlib is currently using ps, which is a non-GUI backend, so cannot show the figure

This is not in a jupyter notebook so this is not a duplicate of this question, but my code is:
from gluoncv import model_zoo, data, utils
from matplotlib import pyplot as plt
...
plt.show()
The error I'm getting is:
/figure.py:445: UserWarning: Matplotlib is currently using ps, which is a non-GUI backend, so cannot show the figure.
% get_backend())
I created a repl at https://repl.it/#shamoons/WelloffHarmfulMineral
If it matters, I'm using OS X. What do I need to do to get the image to show?
You can use
matplotlib.use("TkAgg")
instead of
matplotlib.use("PS")
when developing on MacOS.
Please note that the import should be before importing plt, like this:
import matplotlib
matplotlib.use('TkAgg')
from matplotlib import pyplot as plt
matplotlib.use('PS') and plt.show() are mutually exclusive. You need to decide:
Do you want to show the figure on screen? Solution: Remove the line matplotlib.use('PS').
Do you want to use the PS backend? This seems unlikely, because there is rarely a reason to set the backend to something non-interactive unless working on a server. Anyways, solution: Replace plt.show() by plt.savefig("filname.ps").

importing seaborn changes matplotlib graphs [duplicate]

I am trying to use seaborn, because of its distplot function. But I prefer the default matplotlib settings. When I import seaborn, it changes automatically the appearance of my figure.
How can I use seaborn functions without changing the look of the plots?
Version 0.8 (july 2017) changed this behaviour. From https://seaborn.pydata.org/whatsnew.html#v0-8-0-july-2017:
The default (seaborn) style is no longer applied when seaborn is
imported. It is now necessary to explicitly call set() or one or more
of set_style(), set_context(), and set_palette(). Correspondingly, the
seaborn.apionly module has been deprecated.
For older versions, Import seaborn like this:
import seaborn.apionly as sns
and then you should be able to use sns.distplot but maintain the default matplotlib styling + your personal rc configuration.
According to documentation reset_orig restore all RC params to original settings:
import seaborn as sns
# reset RC params to original
sns.reset_orig()

Importing seaborn in python script messing up plot style

Attached below are two plots. The only difference in the script that produced them is that the second one had an additional line:
import seaborn as sns
I am not setting any seaborn style yet. Just importing seaborn is changing plot style though, even in plots not using seaborn. Is there any way I can import seaborn (to be used in other plots), and not have the style changed for plots that do not use it?
Check this
import seaborn.apionly as sns or from seaborn.apionly import lmplot
http://stanford.edu/~mwaskom/software/seaborn/whatsnew.html

Figure-specific vs general properties in matplotlib

I am trying to understand how methods and attributes are organized in matplotlib. For example, say I have a figure:
import matplotlib.pyplot as plt
my_fig = plt.imshow(image)
I have noticed that some figure properties are set via module methods, e.g.:
plt.axis('off')
while others are set for the figure itself using object methods:
my_fig.set_cmap('hot')
Can figure properties be specified in either way?
How can I turn off the axis by calling methods on my object my_fig?
The plt methods are part of the pyplot API, which is intended to provide Matlab-like convenience for interactive use (and certainly appears to be very influenced by Matlab). But it's just one small facet of the whole matplotlib API (which is much more OOP). In practice I seem to end up mixing them both myself in SW; it's largely a matter of taste whether you go through the pyplot API or access the objects. pyplot is certainly very convenient although as you want to do more complex/exotic things you'll find what you can do with pyplot alone limited and you'll need to get to know at least the full API's Axes, Figure, Legend and Path objects better.
Pyplot is a collection of command style functions that make matplotlib work like MATLAB, matplotlib.figure.Figure is part of the object-oriented API.
In most cases you can configure figure settings via itself like this:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
image=mpimg.imread('stinkbug.png')
my_fig = plt.imshow(image)
my_fig.axes.axes.get_xaxis().set_visible(False)
my_fig.axes.axes.get_yaxis().set_visible(False)
plt.show()
enter code here
required stinkbug.png:
result:

Categories

Resources