-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX/ENH: Introduce a monolithic legend handler for Line2D #11358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
596f20a
33f8129
b195db7
eb07e9b
5fa4ad9
ce7fd79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Change of the (default) legend handler for Line2D instances | ||
----------------------------------------------------------- | ||
|
||
The default legend handler for Line2D instances (`.HandlerLine2D`) now | ||
consistently exposes all the attributes and methods related to the line | ||
marker (:ghissue:`11358`). This makes easy to change the marker features | ||
after instantiating a legend. | ||
|
||
.. code:: | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
fig, ax = plt.subplots() | ||
|
||
ax.plot([1, 3, 2], marker="s", label="Line", color="pink", mec="red", ms=8) | ||
leg = ax.legend() | ||
|
||
leg.legendHandles[0].set_color("lightgray") | ||
leg.legendHandles[0].set_mec("black") # marker edge color | ||
|
||
The former legend handler for Line2D objects has been renamed | ||
`.HandlerLine2DCompound`. To revert to the behavior that was used before | ||
Matplotlib 3, one can use | ||
|
||
.. code:: | ||
|
||
import matplotlib.legend as mlegend | ||
from matplotlib.legend_handler import HandlerLine2DCompound | ||
from matplotlib.lines import Line2D | ||
|
||
mlegend.Legend.update_default_handler_map({Line2D: HandlerLine2DCompound()}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -801,8 +801,13 @@ def draw(self, renderer): | |
# subsample the markers if markevery is not None | ||
markevery = self.get_markevery() | ||
if markevery is not None: | ||
try: | ||
transform = self.axes.transAxes | ||
except AttributeError: | ||
# Typically in the case of a **figure** legend. | ||
transform = self.get_transform() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should just be set to None (or IdentityTransform)? I don't know if we really support float markeverys for figure-level artists (this PR only requires support for list-of-indexes markeverys), so setting it to None to throw something (in the |
||
subsampled = _mark_every_path(markevery, tpath, | ||
affine, self.axes.transAxes) | ||
affine, transform) | ||
else: | ||
subsampled = tpath | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps use one of .. note:: or .. versionadded:: or .. seealso:: (http://www.sphinx-doc.org/en/stable/markup/para.html#paragraph-level-markup). The latter could also be a See also numpydoc section.