简体   繁体   English

seaborn (distplot) yaxis 可以自动重新缩放吗?

[英]Can a seaborn (distplot) yaxis be automatically rescaled?

Can a Seaborn distplot be set to automatically re-scale the yaxis to capture the maximum y extent of multiple plotted datasets?可以将Seaborn distplot设置为自动重新缩放 yaxis 以捕获多个绘制数据集的最大 y 范围吗?

When doing batches of plots using Seaborn , sometimes it is unavoidable that data is provided without an increasing maximum frequency value.使用Seaborn进行批量绘图时,有时不可避免地会在不增加最大频率值的情况下提供数据。 When this happens the created plot yaxis cuts off data.发生这种情况时,创建的绘图 yaxis 会切断数据。 However, sns.distplot() is fine if data is provided with increasing maximum.但是,如果提供的数据具有增加的最大值,则sns.distplot()很好。

This can be fixed via Matplotlib.patches or just by calling ax.autoscale() (Thanks@ImportanceOfBeingErnest for the later suggestion), but either seems "kludgey"...这可以通过Matplotlib.patches或仅通过调用ax.autoscale()来修复(感谢@ImportanceOfBeingErnest为后来的建议),但要么看起来“笨拙”......

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()

(也成功)

This was an issue in Seaborn (0.8.0) and a fix has been a submitted on github .这是Seaborn (0.8.0) 中的一个问题,并且已在github 上提交了修复程序。

If you also see this issue please update just Seaborn (>= version 0.8.1 ).如果您也看到此问题,请仅更新 Seaborn(>=版本 0.8.1 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM