Use Axes objects created individually with seaborn

It is seaborn that wraps matplotlib, but drawing functions such as seaborn.distplot refer to the Axes object that is created globally when matplotlib is imported by default.

By passing the individually created Axes object to the ax keyword argument as shown below, you can refer to this.

python


import matplotlib.pyplot as plt
import seaborn as sns

fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1) #Explicitly create Axes
sns.distplot(data, ax=ax1) #Refer to ax1

By the way, the default behavior is equivalent to: plt.gca () returns the (currently active) globally referenced Axes object.

sns.distplot(data, ax=plt.gca())

Recommended Posts

Use Axes objects created individually with seaborn
Use mecab-ipadic-neologd with igo-python
Use ansible with cygwin
Use pipdeptree with virtualenv
[Python] Use JSON with Python
Use Mock with pytest
Use indicator with pd.merge
Use Gentelella with django
Use mecab with Python3
Use tensorboard with Chainer
Use DynamoDB with Python
Use pip with MSYS2
Use Python 3.8 with Anaconda
Use pyright with Spacemacs
Use python with docker
Use TypeScript with django-compressor
Use LESS with Django
Use MySQL with Django
Use Enums with SQLAlchemy
Use tensorboard with NNabla
Use GPS with Edison
Adjust axes with matplotlib
Use nim with Jupyter