【问题标题】:AttributeError while doing two plots on a jupyther notebook cell在 jupyter 笔记本单元格上进行两个绘图时出现 AttributeError
【发布时间】:2017-08-08 01:22:40
【问题描述】:

我是用seaborn和matplotlib做图的,一个是箱线图:

ax = sns.boxplot(x=data["MEDV"])

另一个是直方图,我在其中更改轴的比例:

g = sns.distplot(data['MEDV'])  
plt.ticklabel_format(style='sci', axis='both', scilimits=(0,0))

如果我在不同的单元格上制作它们,这两个图都可以正常工作,但如果我使用相同的单元格:

ax = sns.boxplot(x=data["MEDV"])

g = sns.distplot(data['MEDV'])  
plt.ticklabel_format(style='sci', axis='both', scilimits=(0,0))

我收到以下错误:

AttributeError: This method only works with the ScalarFormatter.

【问题讨论】:

  • 这个问题没有完整的例子,但我想问题是箱线图在图上放置了文本刻度标签,无法以科学计数法呈现(因为它们不是数字)。

标签: matplotlib jupyter-notebook seaborn


【解决方案1】:

如果你想要两个子图,每个子图中都有一个图:

fig, (ax, ax2) = plt.subplots(ncols=2)
sns.boxplot(x=data, ax=ax)

sns.distplot(data, ax=ax2)  
plt.ticklabel_format(style='sci', axis='both', scilimits=(0,0))

如果你想要两个不同的数字,每个图一个:

plt.figure()
sns.boxplot(x=data)

plt.figure()
sns.distplot(data)  
plt.ticklabel_format(style='sci', axis='both', scilimits=(0,0))

【讨论】:

    猜你喜欢
    • 2022-07-21
    • 2016-02-04
    • 1970-01-01
    • 1970-01-01
    • 2016-01-14
    • 2021-01-11
    • 2015-10-15
    • 1970-01-01
    • 2020-05-23
    相关资源
    最近更新 更多