How To Despine A Matplotlib And Seaborn Axes
I'm having difficulty turning the axes on and off in plots, and sizing my axes appropriately. I've followed several threads and my method is: f1=plt.figure(1,(3,3)) ax=Subplot(f1,1
Solution 1:
Can you be more specific what's needed?
You can remove the spine with:
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['bottom'].set_visible(False)
But it sounds like you might be referring to ticks on the spine...
Solution 2:
I highly recommend looking at the seaborn
library for this sort of manipulation. Removing spines is as easy as sns.despine()
.
For example, to make a spineless chart with a white background I might write
import pandas as pd
import numpy as np
import seaborn as sns
df2 = pd.Series([np.sqrt(x) for x inrange(20)])
sns.set(style="nogrid")
df2.plot()
sns.despine(left=True, bottom=True)
to get
Have a look at the linked documentation for more details. It really does make controlling matplotlib aesthetics dramatically easier than writing all the code out manually.
Post a Comment for "How To Despine A Matplotlib And Seaborn Axes"