Reputation: 85
I had an issue when I was trying to plot dual axis plot using seaborn in a jupyter notebook Important note: The code worked very well with Python 2.
After upgrading to Python 3 with anaconda, I get the foolowing error message:
/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)
Here's the output image of my code:
My code:
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()
Upvotes: 3
Views: 3063
Reputation: 40737
I don't see how your code could have worked with Python2, but that's beside the point. The error message clearly tells you that catplot
does not take an ax=
argument. If you want to plot on subplots, you have to use the underlying plotting function (in the first case, countplot
as the error suggests)
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])
Upvotes: 4