Reputation: 1199
I would like to plot the following dataframe with xtick labels rotated while also having a tight, despined layout (using tight_layout()
from matplotlib and despine
from seaborn). the following does not work because the labels do not show up:
import matplotlib.pylab as plt
import seaborn as sns
import pandas
df = pandas.DataFrame({"x": ["XYZ1", "XYZ2", "XYZ3", "XYZ4"],
"y": [0, 1, 0, 1]})
plt.figure(figsize=(5,5))
sns.set_style("ticks")
g = sns.pointplot(x="x", y="y", data=df)
sns.despine(trim=True, offset=2)
g.set_xticklabels(g.get_xticklabels(), rotation=55, ha="center")
plt.tight_layout()
it produces:
the xtick labels ("XYZ1", "XYZ2", ...) do not appear. if i remove despine the ticks appear but then not despined. if i change ticks before despine/tight_layout, they appear but are not rotated. how can this be done?
Upvotes: 1
Views: 4240
Reputation: 339280
on my machine the following works
import matplotlib.pylab as plt
import seaborn as sns
import pandas
df = pandas.DataFrame({"x": ["XYZ1", "XYZ2", "XYZ3", "XYZ4"],
"y": [0, 1, 0, 1]})
plt.figure(figsize=(5,5))
sns.set_style("ticks")
g = sns.pointplot(x="x", y="y", data=df)
sns.despine(trim=True, offset=2)
g.set_xticklabels(df['x'], rotation=55, ha="center")
plt.tight_layout()
plt.show()
and produces
Upvotes: 3