Reputation: 35
Using seaborn to plot a figure,
Here is the code:
import seaborn as sns
import matplotlib.pyplot as plt
g = sns.relplot(x="date", y="revenue", hue="groups", kind="line", data=df_grp_1)
And use the following code to modify the x ticks:
g.set_xticks(range(len(df_grp_1)))
g.set_xticklabels(['2019-04-15''2019-04-22', '2019-04-29', '2019-05-06','2019-05-13','2019-05-20'])
but it gives me this error:'FacetGrid' object has no attribute 'set_xticks'
How can I fix it?
Upvotes: 0
Views: 326
Reputation: 645
The relplot returns a FacetGrid, you need an axis. If you were to try dir(g) you can see that the FacetGrid has an ax. So your error should go away if you were to change your code to this:
g.ax.set_xticks(range(len(df_grp_1)))
g.ax.set_xticklabels(['2019-04-15''2019-04-22', '2019-04-29', '2019-05-06','2019-05-13','2019-05-20'])
Upvotes: 1