在jupyther笔记本单元格上进行两个绘图时出现AttributeError

时间:2017-08-08 01:22:41

标签: matplotlib jupyter-notebook seaborn

我使用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.

1 个答案:

答案 0 :(得分: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))

enter image description here

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

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

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

enter image description here