I have plot in Python matplotlib:
from matplotlib import pyplot as plt
data = [1, 5, 2, 1, 1, 4, 3, 1, 7, 8, 9, 6, 1]
plt.plot(data)
Is there any way to hide axis lines and labels except min and max y-axis label? I know about plt.axis("off")
, however I would like to show first and last label on y-axis.
The current plot is on the left of the image below and desired plot on the right.
Here you format the borders and ticks to hide them and then set the y-ticks explicitly:
from matplotlib import pyplot as plt
data = [1, 5, 2, 1, 1, 4, 3, 1, 7, 8, 9, 6, 1]
fig, ax = plt.subplots()
ax.plot(data)
for side in ['top','right','bottom','left']:
ax.spines[side].set_visible(False)
ax.tick_params(axis='both',which='both',labelbottom=False,bottom=False,left=False)
ax.set_yticks([min(y),max(y)])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With