Reputation: 57
I am encountering a problem when using despine() with seaborn. I am trying to use two y axes, and am only removing the neccesary spines for each axis, but despine() also removes the tick marks from the right hand vertical axis. A minimum working example is below:
import numpy as np
import matplotlib.pyplot as plt
import seaborn
seaborn.set()
seaborn.set_style("ticks")
fig, ax1 = plt.subplots(figsize=(6,2))
ax2 = ax1.twinx()
ax1.plot(np.array([0,1,3]))
ax2.plot(np.array([2,2,1]))
seaborn.despine(ax=ax2, left=True, right=False, trim="True")
seaborn.despine(ax=ax1, bottom=True, left=False, right=True, trim="true")
plt.show()
As you can see in the image below, this has also removed the tick marks from the right hand vertical axis (which I do not want).
Any insights into how I would fix this would be highly appreciated!
Upvotes: 1
Views: 825
Reputation: 49002
The way twinx
is implemented, the ticks on the second y axis actually belong to the "left" spine, so you need
seaborn.despine(ax=ax2, left=False, right=False, trim="True")
Upvotes: 3