You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the Artist tutorial, it says that Axes have a legends attribute that is "A list of Legend instances". However, my Axes don't seem to have this attribute using matplotlib v2.0.
Is the tutorial wrong or is there a regression in matplotlib?
Checking out that commit and searching for legends gives:
✔ ~/source/p/matplotlib [:f0f28a3ef|⚑ 8]
18:41 $ git grep legends
CHANGELOG:2005-10-26 Added support for scatter legends - thanks John Gill
doc/users_guide/artist_api_tut.txt:legends A list of Figure Legend instances (different from Axes.legends)
doc/users_guide/artist_api_tut.txt:ax.legend - axes legends Legend ax.legends
doc/users_guide/artist_api_tut.txt:legends A list of Legend instances
docs/users/artists.rst:legends A list of Figure Legend instances (different from Axes.legends)
docs/users/artists.rst:ax.legend - axes legends Legend ax.legends
docs/users/artists.rst:legends A list of Legend instances
examples/pylab/legend_auto.py:algorithm, but shows lots of different ways to create legends so is
lib/matplotlib/axes.py: legends), linewidth, anitialising, marker face color, etc. Here is an
lib/matplotlib/backends/backend_emf.py: # legends where the circles are small anyway, and it is
lib/matplotlib/figure.py: children.extend(self.legends)
lib/matplotlib/figure.py: self.legends = []
lib/matplotlib/figure.py: for legend in self.legends:
lib/matplotlib/figure.py: 'best' : 0, (currently not supported for figure legends)
lib/matplotlib/figure.py: self.legends.append(l)
lib/matplotlib/legend.py: 'best' : 0, (only implemented for axis legends)
lib/matplotlib/legend.py: 'best' : 0, (only implemented for axis legends)
lib/matplotlib/legend.py: codes = {'best' : 0, # only implemented for axis legends
Then assuming I am in the one-legend-per-Axes scenario, is accessing the Axes's legend via the legend_ instance variable the officially supported (and more importantly – safe) method?
Oh, didn't realize there was a get_legend() method. I think the trailing _ is to avoid conflict with the legend() method, although it's an interesting choice to have it as legend_ instead of _legend.
Activity
tacaswell commentedon Mar 2, 2017
I think the tutorial has been wrong for a very long time (
Figureobjects do havelegendsattribute though).As near as I can tell
Axesnever had anlegendsattribute and the legends guide even explains a work around to the hard-coded 1:1 mapping of legend to axes (http://matplotlib.org/users/legend_guide.html#multiple-legends-on-the-same-axes).That particular line goes back to 2008 (f0f28a3).
Checking out that commit and searching for legends gives:
katzenbaer commentedon Mar 3, 2017
Then assuming I am in the one-legend-per-Axes scenario, is accessing the
Axes's legend via thelegend_instance variable the officially supported (and more importantly – safe) method?tacaswell commentedon Mar 3, 2017
There is a
get_legend()method that is what should probably be used. Not sure what the trailing_means here...katzenbaer commentedon Mar 3, 2017
Oh, didn't realize there was a
get_legend()method. I think the trailing_is to avoid conflict with thelegend()method, although it's an interesting choice to have it aslegend_instead of_legend.