We’ve written a style system that lives on top of the MPL code that has a similar syntax to what you’re proposing. A simple example:
If people think this something worthwhile that could be incorporated back into MPL, we can work on making the code for the style system available.
···
From: jamesramm [jamessramm@…149…]
Sent: Sunday, August 10, 2014 12:40 AM
To: matplotlib-devel@lists.sourceforge.net
Subject: Re: [matplotlib-devel] MEP26: Artist-level stylesheets
I have updated MEP26 to include discussion on ‘decoupling’ the style from
artists and having a generic Style class.
(copied over from the github issue):
I have been thinking that a good way to get stylesheets in, would be if the
‘style’ of an artist was entirely independent.
I.E a single property which points to some kind of ‘style’ object. This way,
style objects could be created on their own (programatically, or by some
other means (Stylesheets!)) and then applied to artists at will
(programatically, or by some other means (a stylesheet parser…)).
Then I thought…when it comes to drawing, the style is entirely
independent - it has been transferred to the GraphicsContext
object. So
all that is needed is to expose this object at the artist level and we can
create styles!
I created a very minimal example to explain here:
https://github.com/JamesRamm/mpl_experiment
Basically, it just provides a Style
class (which is just
GraphicsContextBase
propertified and with a new function to generate one
from a dict) and a minimal reimplementation of Line2D and Text to show how
it would be used for both.
Just run run.py (and have a look at it) to see how the user would use style
objects.
(Note it is a bit convoluted as I have not added any axes plotting routines,
so a Line2D needs to be manually created and added).
Basically, this involves reimplementing the draw
method to use the style
property rather than creating a new GraphicsContext
instance.
It also has the benefits that you could create 1 style object and apply it
to multiple artists, or tweak a couple of properties on each…which is
nicer than using individual get/set methods on artists (IMO).
So the API could potentially become something like:
arts = axes.plot(xdata, ydata) #Note not providing any ‘style’ info
myStyle = Style.from_dict({‘color’: ‘#484D7A’, ‘linewidth’: 1.9,
‘linestyle’: ‘dashed’})
arts.style = myStyle
arts.style.color = ‘#FFFFFF’
or:
myStyle = Style()
axes.plot([0,1],[0,1], style = myStyle)
–
View this message in context: http://matplotlib.1069221.n5.nabble.com/MEP26-Artist-level-stylesheets-tp43664p43770.html
Sent from the matplotlib - devel mailing list archive at Nabble.com.
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel