Reputation: 1146
Can a Seaborn distplot be set to automatically re-scale the yaxis to capture the maximum y extent of multiple plotted datasets?
When doing batches of plots using Seaborn, sometimes it is unavoidable that data is provided without an increasing maximum frequency value. When this happens the created plot yaxis cuts off data. However, sns.distplot()
is fine if data is provided with increasing maximum.
This can be fixed via Matplotlib.patches
or just by calling ax.autoscale()
(Thanks @ImportanceOfBeingErnest for the later suggestion), but either seems "kludgey"...
Simple worked example:
# Import modules
import numpy as np
from scipy.stats import truncnorm
import matplotlib.pyplot as plt
import seaborn as sns; sns.set(color_codes=True)
# Make some random data (credit: [@bakkal's Answer][3])
scale = 3.
range = 10
size = 100000
X = truncnorm(a=-range/scale, b=+range/scale, scale=scale).rvs(size=size)
# --- first time to show issue
# Now plot up 1st set of data (with first dataset having high Y values)
ax= sns.distplot( X*4 )
# Now plot up two more
for i in np.arange(1, 3):
sns.distplot( X*i, ax=ax )
plt.show()
# --- Second time with a "kludgey" fix
ax = sns.distplot( X*4 )
# Now plot up two more
for i in np.arange(1, 3):
sns.distplot( X*i, ax=ax )
# Now force y axis extent to be correct
ax.autoscale()
plt.show()
# --- Third time with increasing max in data provided
ax= sns.distplot( X )
# Now plot up two more
for i in np.arange(2, 4 ):
sns.distplot( X*i, ax=ax )
plt.show()
Upvotes: 2
Views: 4326
Reputation: 1146
This was an issue in Seaborn (0.8.0) and a fix has been a submitted on github.
If you also see this issue please update just Seaborn (>= version 0.8.1).
Upvotes: 2