小编Tro*_*roy的帖子

使用对数刻度注释 seaborn distplot 会引发错误

%matplotlib inline
import seaborn as sns
titanic = sns.load_dataset('titanic')
ax1 = sns.distplot(titanic['fare'], kde=False, bins=15,)

# ax1.set_yscale('log')

for p in ax1.patches:
    ax1.annotate(
        s=f"{p.get_height():1.0f}",
        xy=(p.get_x() + p.get_width() / 2., p.get_height()), 
        xycoords='data',
        ha='center', 
        va='center', 
        fontsize=11, 
        color='black',
        xytext=(0,7), 
        textcoords='offset points',
    )
Run Code Online (Sandbox Code Playgroud)

上面的代码绘制了泰坦尼克号数据集的直方图Fare,其中每个条形都使用 注释了其值ax1.annotate。当我想将 y 刻度设置为 logc 时,麻烦就来了——取消注释该set_yscale行并运行它;它抛出一个错误说:

ValueError:378x84035 像素的图像尺寸太大。每个方向都必须小于 2^16。

也许应该更改 xycoords 参数,但我也不太确定要更改什么。

我使用的是Python 3.7.2,seaborn的版本是0.9.0。Matplotlib 版本 3.0.2,我使用的是内联后端。

python matplotlib python-3.x seaborn

6
推荐指数
1
解决办法
3263
查看次数

标签 统计

matplotlib ×1

python ×1

python-3.x ×1

seaborn ×1