Issue
Calling plt.spines.set_position()
appears to be overwriting the tick labels rotation, but not the labels themselves. Before I call .set_position()
, rotation=
seems to be working as expected:
df = pd.DataFrame({
'type': ['A', 'B', 'C'],
'height': [1, 2, 3]
})
fig, ax = plt.subplots(1, figsize=(8,2))
df.plot(kind='bar', ax=ax)
ax.set_xticklabels(['zero', 'one', 'two'], rotation=90)
When then when I call .set_position()
, the labels still appear, but they revert to their original rotation:
ax.spines['bottom'].set_position(('outward', 10))
Is there a way to call .set_position()
while retaining the label rotation?
Solution
It's simple. Put the set_xticklabels statement after set_position():
df = pd.DataFrame({
'type': ['A', 'B', 'C'],
'height': [1, 2, 3]
})
fig, ax = plt.subplots(1, figsize=(8,2))
df.plot(kind='bar', ax=ax)
ax.spines['bottom'].set_position(('outward', 10))
ax.set_xticklabels(['zero', 'one', 'two'], rotation=90)
plt.show()
Answered By - pakpe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.