-
-
Notifications
You must be signed in to change notification settings - Fork 404
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
Refactored matplotlib ElementPlots by adding higher-level API #438
Conversation
Great! Will this put us in a position where we can document these classes and their methods properly? Maybe even write some sort of developer documentation about it? |
The general idea behind this PR is to simplify the implementation of matplotlib plotting classes to reduce redundancy and make it easier to implement new matplotlib plotting classes. Previously the main methods to implement a plotting class were:
To make this old API workable a lot of plotting classes implemented custom workarounds, e.g. so that each plot didn't have two separate implementations to unpack the element. However in developing the bokeh backend I came up with a better solution. I've now ported some of the ideas from the bokeh backend to matplotlib. It's important to mention that because the matplotlib API is sometimes awkward this new API is entirely optional and some plots will retain the old API for now. The general idea is to separate the unpacking of the data and keyword arguments from the element from the actual plotting. The ElementPlot baseclass now has a default implementation of The signature for these methods is the following:
Overall implementing all this roughly halves the plotting code required and in future when matplotlib provides a better interface to update existing artists, it should be possible to feed he output of |
192f63e
to
17e2778
Compare
04e5f6d
to
5d0c781
Compare
5d0c781
to
8614435
Compare
Okay I was wrong the 3d stuff wasn't the only change. There are three display changes:
The first two are fixes/improvements and I really don't know what to do about 3). All three are very minor and purely aesthetic changes, so I'll focus on documenting now. |
|
||
ranges = self.compute_ranges(self.hmap, key, ranges) | ||
ranges = match_spec(element, ranges) | ||
def init_artist(self, ax, plot_data, plot_kwargs): |
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.
Should be called init_artists
if multiple artists can be initialized here.
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.
Agreed, will rename.
return self._finalize_axis(self.keys[-1], ranges=ranges) | ||
if element.get_dimension(self.size_index): | ||
sizes = element.dimension_values(self.size_index) | ||
ms = style.pop('s') if 's' in style else plt.rcParams['lines.markersize'] |
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.
Happy to use rcParams
here? I thought rcParams
could sometimes be tricky...
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.
Hmm I don't think there are any particular issues but I guess we could require that a 's' is supplied to apply points scaling.
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.
I think it's best to postpone this to another PR as to avoid changing any more test data.
Made a few minor comments but overall it does seem like a nice improvement. As it is a fairly large PR, I have a few general comments:
Anyway, I'm happy to merge once these issues are addressed. Frankly, I expect we will find bugs related to this refactor but I do think this is worth having cleaner, more easily understandable code. |
I've carefully reviewed the test data changes and listed the 3 things that have changed above. The only thing I'm sort of worried about is the VectorField changes as their width has changed slightly and I can't figure out why.
Definitely a good idea.
We've always been putting the axis and figure in it, and apart from that it's generally only used for artists. The artist key is treated somewhat specially as that is where the legend code expects to find the artist and by default that is what gets removed if you don't define an |
I understand this is ready for a merge and the tests are passing. I'm glad that the plotting code will be clearer to understand after this! |
Refactored matplotlib ElementPlots by adding higher-level API
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This refactor avoids a lot of the duplication that has spread across all existing matplotlib plots. It should also make it simpler for a user to create a new plot. I'll summarize the overall API once I've worked on it a little bit more.