无法使用seaborn绘制双坐标轴

3

在jupyter笔记本中使用seaborn绘制双坐标轴图时,我遇到了一个问题。重要提示:该代码在Python 2中运行非常良好。

升级到anaconda的Python 3后,我收到了以下错误消息:

/Users/enyi/opt/anaconda3/lib/python3.7/site-packages/seaborn/categorical.py:3720: UserWarning: catplot is a figure-level function and does not accept target axes. You may wish to try countplot
  warnings.warn(msg, UserWarning)

以下是您的代码的输出图像:

我的代码输出结果

这是我的代码:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

df = pd.read_csv('tips.csv')

fig, ax = plt.subplots(1,2,figsize = (10,5))

sns.catplot(x='sex', hue = 'group', data= df, kind = 'count', ax=ax[0])
sns.catplot(x='sex', y='conversion',hue = 'group', data= df, kind = 'bar',ax=ax[2])

plt.show()
1个回答

4
我不明白你的代码如何在Python2中运行,但那已经无关紧要了。错误信息明确告诉你catplot不接受ax=参数。如果你想在子图上绘图,就必须使用底层的绘图函数(就像第一个例子中,根据错误提示使用countplot)。
fig, ax = plt.subplots(1,2,figsize = (10,5))
sns.countplot(x='sex', hue = 'group', data= df, ax=ax[0])
sns.barplot(x='sex', y='conversion',hue = 'group', data= df,ax=ax[1])

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接