10

I am trying to understand the matplotlib API. I have seen many examples like this:

...
fig, (ax0, ax1) = plt.subplots(nrows=2)
ax1.spines['right'].set_visible(False)
...
ax1.xaxis.set_ticks_position('bottom')
...

(full example: http://matplotlib.org/examples/ticks_and_spines/spines_demo.html )

I understand what it does but I was unable to find in the API the spines and xaxis attributes of ax0 and ax1 that was used to retrieve the xaxis and the spines (although there is a documented get_xaxis() method but nothing for the spines). Of course now I know it for that particular case but are there other hidden attributes? Or perhaps I have not read the documentation correctly? Where these attributes come from? Maybe they were added by fig.subbplots? I would like to have a list of all public attributes for basic matplotlib objects. Do I really have to resort to the dir python builtin and guess the signification from the names?

1 Answer 1

2

pyplot is a procedural style interface/abstraction over matplotlib's OO API. So pyplot internally creates/manages necessary objects required for plotting. Every object(e.g Line,Axis,Axes ) is an Artist for matplotlib. Each artist has attributes. Have a look over

http://matplotlib.org/users/artists.html

Sign up to request clarification or add additional context in comments.

2 Comments

I see the idea, while this page is helpful, it does not completely document the features above. According to this page, the properties are set with an old fashioned (dixit the documentation) setter or getter attribute; while here we do not use ax.get_spines() but well a.spines (but get_xaxis() work). Moreover no spines property is documented. I thus assume it is documentation deficit.
It looks like that document is not up to date.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.