My question
I would like to know what matplotlib's SubplotZero()
function does, knowing that it is not referenced in matplotlib's documentation, but is used in at least three examples of the matplotlib website (here for instance). Also, since it is not present in the documentation is it recommended and safe to use? Or is there a risk it might be removed in future versions of matplotlib?
The context
I want to make a plot with matplotlib that displays the "zero" axis. Examples of such plots are shown in matplotlib's examples
page. This is done with
ax.axis["xzero"].set_visible(True)
However, writing
ax = plt.gca()
ax.axis["xzero"].set_visible(True)
yields error
ax.axis["xzero"].set_visible(True)
TypeError: 'method' object is not subscriptable
Instead, as was shown in the examples, one is supposed to write (Note: actually there is another way to achieve the same result: see @ImportanceOfBeingErnest's answer)
from mpl_toolkits.axisartist.axislines import SubplotZero
fig = plt.figure()
ax = SubplotZero(fig, 1, 1, 1)
fig.add_subplot(ax)
ax.axis["xzero"].set_visible(True)
which indeed works. However, I was curious to understand what the SubplotZero()
function did, and why it existed in the first place (after all why is it needed at all?). So I went to look in the documentation and realized it was not part of it!
Does someone know the answers to those questions?
SubplotZero
is different to a normalAxes
instance: github.com/matplotlib/matplotlib/blob/master/lib/mpl_toolkits/…