Skip to content

Combine withEffect PathEffect definitions.#15515

Merged
timhoffm merged 1 commit into
matplotlib:masterfrom
anntzer:witheffect
Mar 14, 2020
Merged

Combine withEffect PathEffect definitions.#15515
timhoffm merged 1 commit into
matplotlib:masterfrom
anntzer:witheffect

Conversation

@anntzer

@anntzer anntzer commented Oct 25, 2019

Copy link
Copy Markdown
Contributor

PR Summary

could be used in #15458 as well.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@timhoffm timhoffm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, docstring inheritance does not work for the draw_path() method of the generated class. Compare
https://matplotlib.org/devdocs/api/patheffects_api.html#matplotlib.patheffects.withStroke.draw_path
and
https://9440-7439715-gh.circle-artifacts.com/0/home/circleci/project/doc/build/html/api/patheffects_api.html#matplotlib.patheffects.withStroke.draw_path

Apart from that, I have the concern that this is obscuring things more. withStroke = _make_with_effect(Stroke) does in no way indicate that withStroke is actually a class. This needs better naming and documentation.

@anntzer

anntzer commented Oct 26, 2019

Copy link
Copy Markdown
Contributor Author

Re docs: good catch, this is actually a limitation of the implementation of inspect.getdoc (which can be fixed at least in this case), I'll open a bug report on the python tracker. In the meantime I just inherited the docstring manually.
Re naming: _make_with_effect_patheffectsubclass? Happy for more proposals.

@timhoffm

Copy link
Copy Markdown
Member

What about withStroke = _subclass_with_normal(effect_class=Stroke)?

@anntzer

anntzer commented Oct 27, 2019

Copy link
Copy Markdown
Contributor Author

Sounds good, changed accordingly.

@anntzer

anntzer commented Oct 27, 2019

Copy link
Copy Markdown
Contributor Author

(the docstring inheritance issue is at https://bugs.python.org/issue38603)

Comment thread lib/matplotlib/patheffects.py Outdated
Comment thread lib/matplotlib/patheffects.py Outdated

withEffect.__name__ = f"with{effect_class.__name__}"
withEffect.__doc__ = f"""
Adds a `.{effect_class.__name__}` and then draws the original Artist to

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been struggling to understand what the with... classes are and what they are good for (path effect newbie here). Therefore I'm a bit picky on docs. I propose something like this (Please check ReST syntax and line length. This is a bit difficult in the github interface):

"""
A shortcut PathEffect for applying `.{effect_class.__name__}` and then
drawing the original Artist.

Examples
--------
With this class you can use ::

    artist.set_path_effects([path_effects.with{effect_class.__name__}()])

as a shortcut for ::

    artist.set_path_effects([path_effects.{effect_class.__name__}(),
                             path_effects.Normal()])
"""

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking for example the path effect proposed at #15458, using just path_effects=[TickedStroke(...)] would only draw the ticks, not the "original" path; using path_effects=[withTickedStroke(...)] draws both the original path and not the Stroke. Your suggestion is fine, adding it.

@timhoffm

Copy link
Copy Markdown
Member

Bonus points if you add a link to https://matplotlib.org/3.1.1/tutorials/advanced/patheffects_guide.html in the module docstring.

@anntzer

anntzer commented Oct 27, 2019

Copy link
Copy Markdown
Contributor Author

all suggestions integrated.

@timhoffm timhoffm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plus bonus points for the tutorial reference 😄.

super().draw_path(renderer, gc, tpath, affine, rgbFace)
renderer.draw_path(gc, tpath, affine, rgbFace)

withEffect.__name__ = f"with{effect_class.__name__}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So... if you have to do this big song and dance for the docs, is this change really worth it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more worth it if we keep adding new patheffects and repeat this code pattern again and again, e.g. #15458.

@anntzer

anntzer commented Mar 14, 2020

Copy link
Copy Markdown
Contributor Author

rebased

@timhoffm timhoffm added this to the v3.3.0 milestone Mar 14, 2020
@timhoffm timhoffm merged commit 32f08df into matplotlib:master Mar 14, 2020
@anntzer anntzer deleted the witheffect branch March 14, 2020 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants