I created a subplot with multiple rows and columns and they share their x-axis. After deleting the bottom right-most ax, the ax above it does not show the x-axis values. How can I make these x-axis values visible on this ax?
What I don't want, is to have to add the top right-most ax later on.
from matplotlib import pyplot as plt
fig, ax = plt.subplots(2, 3, sharex=True, sharey=True)
fig.tight_layout()
fig.delaxes(ax[1, 2])
plt.show()
This is what I get:
This is what I would like to get (this screenshot was altered in paint):
I tried things like:
ax[0,2].xaxis.set_visible(True)
ax[0,2].set_xticks([0, 0.25, 0.5, 0.75, 1])
ax[0,2].set_xticklabels([0, 0.25, 0.5, 0.75, 1])
But none of these helped. Thank you!
CodePudding user response:
One option is:
ax[0, 2].tick_params(labelbottom=True)
CodePudding user response:
Well, do the subplots have to share the x-axis?
If not, you could do something like this:
from matplotlib import pyplot as plt
fig, ax = plt.subplots(2, 3, sharex=False, sharey=True)
fig.tight_layout()
ax[0, 0].xaxis.set_visible(False)
ax[0, 1].xaxis.set_visible(False)
fig.delaxes(ax[1, 2])
plt.show()
If you do need the shared axis, maybe it's possible to move one plot to the bottom row?
from matplotlib import pyplot as plt
fig, ax = plt.subplots(2, 3, sharex=True, sharey=True)
fig.tight_layout()
fig.delaxes(ax[0, 2])
plt.show()