Skip to content
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

[Doc]: legend guide should be OO #20754

Closed
story645 opened this issue Jul 28, 2021 · 2 comments
Closed

[Doc]: legend guide should be OO #20754

story645 opened this issue Jul 28, 2021 · 2 comments
Labels
Documentation Good first issue Open a pull request against these issues if there are no active ones! topic: legend
Milestone

Comments

@story645
Copy link
Member

Documentation Link

https://matplotlib.org/devdocs/tutorials/intermediate/legend_guide.html

Problem

The legend guide is all pyplot interface, which is especially discouraged in the types of examples (complicated, some needing state) in the guide. For example:

from matplotlib.legend_handler import HandlerPatch


class HandlerEllipse(HandlerPatch):
    def create_artists(self, legend, orig_handle,
                       xdescent, ydescent, width, height, fontsize, trans):
        center = 0.5 * width - 0.5 * xdescent, 0.5 * height - 0.5 * ydescent
        p = mpatches.Ellipse(xy=center, width=width + xdescent,
                             height=height + ydescent)
        self.update_prop(p, orig_handle, legend)
        p.set_transform(trans)
        return [p]


c = mpatches.Circle((0.5, 0.5), 0.25, facecolor="green",
                    edgecolor="red", linewidth=3)
plt.gca().add_patch(c)

plt.legend([c], ["An ellipse, not a rectangle"],
           handler_map={mpatches.Circle: HandlerEllipse()})

Suggested improvement

switch the tutorial to OO

Matplotlib Version

3.4.2.post1539+gf8f693922c

Matplotlib documentation version

3.4.2.post1539+gf8f693922c

@story645 story645 added Documentation Good first issue Open a pull request against these issues if there are no active ones! topic: legend labels Jul 28, 2021
@BhaswatiRoy
Copy link

Under legend location can we just add the "best" parameter with a sample of code with output since it is the most commonly used and most important. Also, we can add plots for some more legend locations to make things clearer. Just like the following ss->

Screenshot 2021-07-30 132412

@timhoffm
Copy link
Member

timhoffm commented Aug 7, 2021

Closed by #20792.

@timhoffm timhoffm closed this as completed Aug 7, 2021
@QuLogic QuLogic added this to the v3.5.0 milestone Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Good first issue Open a pull request against these issues if there are no active ones! topic: legend
Projects
None yet
Development

No branches or pull requests

4 participants