The following code snippet produces a line with no visible plot axes and a normal plot with visible axes:
import matplotlib.pyplot as plt
fig, ax = plt.subplots(2)
ax[0].plot([0, 1])
ax[0].set_xlabel('x1')
ax[0].axis('off')
ax[1].plot([1, 0])
ax[1].set_xlabel('x2')
I would like a general way to detect whether the axes of a given axes
instance are visible. I have tried a few things without finding a way to distinguish axes which are visible from those which are hidden by the above method:
for i in range(2):
print('axes set', i,
ax[i].get_frame_on(),
ax[i].xaxis.get_visible(),
ax[i].xaxis.get_alpha())
Results:
('axes set', 0, True, True, None)
('axes set', 1, True, True, None)
As you can see, none of the outputs are different between the subplots with visible and invisible axes.
Given a set of axes
objects which may or may not have been turned off with .axis('off')
, how can I tell which ones are visible?
You can use the axison
attribute of the Axes
object to determine whether the axes
is turned on or off.
if ax.axison:
print 'on'
else:
print 'off'
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