-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Style RC parameter #4240
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
Style RC parameter #4240
Conversation
I get errors from travis that my stylesheets cannot be found... I am not sure how I could get it to work. Also, it is now in the sample_data folder, which I think is not the best location for data that will be used only for tests. Edit: It seems my folder won't install with Edit 2: Tried and find how was imported the |
Thanks for breaking this out into its own PR! A general comment about the tests and sample style files: I think all of the style files are unnecessary. Having tests that depend on values that are in a separate file makes the logic of the tests hard to follow. Instead, I would suggest reusing the |
@@ -501,6 +501,8 @@ def __call__(self, s): | |||
|
|||
# a map from key -> value, converter | |||
defaultParams = { | |||
'style': ['', validate_stringlist], |
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.
As mentioned in the original PR, I don't think it's important to support a list of parent stylesheets---at least not initially. I could be convinced otherwise, but I think it adds complication to the logic.
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.
Actually, getting a list of parent stylesheets is kind of my main idea. This way, you could have really small stylesheets setting only a part of the plot (e.g. only the font, or the lines width) that could be associated to create easily bigger stylesheets.
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.
Personally, I see two broad categories for style sheets: Those focused on aesthetics and those focused on layout (for slides, journal papers, etc.). I think these should be combined at runtime with style.use
. I don't see the need for more fine grained partitioning, but I imagine others would. I don't want to push too much, but I think a simpler initial implementation is a good idea.
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.
On the top on being able to create stylesheets by "cascading" them (it's a very small implementation of cascading...), you could have a style in your matplotlibrc so that you don't have to call the style.use
function every time you create a new script.
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 you're right, actually: Combining multiple stylesheets in your default matplotlibrc
file will probably be a common use case.
That said, I think the implementation might be a bit clearer with a different approach. Have you thought of writing this using recursive dictionary updates instead of looping over parent styles? I've played around with an alternate implementation if you're open to the idea.
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.
Can you explain a bit more on detail about the recursive dictionary update? I'm willing to do the best implementation possible for this, so if this can be cleaner...
Envoyé depuis mon appareil Samsung
-------- Message d'origine --------
De : Tony S Yu notifications@github.com
Date : 22/06/2015 06:58 (GMT+01:00)
À : matplotlib/matplotlib matplotlib@noreply.github.com
Cc : Gilles Marin gillesmarin1706@gmail.com
Objet : Re: [matplotlib] Style RC parameter (#4240)
In lib/matplotlib/rcsetup.py:
@@ -501,6 +501,8 @@ def call(self, s):
a map from key -> value, converter
defaultParams = {
- 'style': ['', validate_stringlist],
I think you're right, actually: Combining multiple stylesheets in your default matplotlibrc file will probably be a common use case.
That said, I think the implementation might be a bit clearer with a different approach. Have you thought of writing this using recursive dictionary updates instead of looping over parent styles? I've played around with an alternate implementation if you're open to the idea.
—
Reply to this email directly or view it on GitHub.
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.
Here's a gist that flattens a dictionary containing a special key pointing to "parent" dictionaries: https://gist.github.com/tonysyu/b02be7df210c4369afa6. That's a generic implementation with nothing specific to matplotlib styles. To use it in this case you could write something like the following:
PARENT_STYLES = 'styles'
flattened_style = flatten_style_dict({PARENT_STYLES: styles})
def flatten_style_dict(styles_dict):
return flatten_inheritance_dict(styles_dict, PARENT_STYLES,
expand_parent=_expand_parent)
def _expand_parent(parent_style):
if cbook.is_string_like(parent_style):
return get_style_parameters(parent_style)
return parent_style
To actually integrate this with the style
module, you'd want to remove the loop from use
and just call update on the flattened_style
dictionary. Note that the current tests won't pass with this function because the order of styles in the PARENT_STYLES
is flipped. If you flip the order of parent styles in your mplstyle
files, the test will pass.
Re-milestoned this as 'proposed next point release' which mean it will not be a blocker for the next point release. This looks like it still has a good deal of work? |
@tacaswell , @Mrngilles , are there any outstanding issues here? |
@WeatherGod TODO :
|
Given that we want to do a feature freeze (today, preferably), do you have On Sun, Jul 12, 2015 at 1:05 PM, Gilles Marin notifications@github.com
|
I have no objection, as this should be working. On July 13, 2015 3:50:00 PM GMT+02:00, Benjamin Root notifications@github.com wrote:
Envoyé de mon appareil Android avec K-9 Mail. Veuillez excuser ma brièveté. |
That very helpful error message means 'nose could not import the module matplotlib.tests.test_style but silently snarfed the exception and are now telling you that the explicitly white listed modules to test do not exist'. Are you using |
I kicked the 2.7 and 3.3 tests, they look like timeout issues we intermittently have with latex |
Indeed the tests for the dictionary flattening function use assert_raise as a context manager. Do you think changing that will make it work? |
Rather than iterating with travis, it is probably easiest to install a 2.6 enviroment with conda and see what is failing on import. |
Yes, I got bitten by this once before. For some reason, assert_raise() is On Tue, Jul 21, 2015 at 2:43 PM, Thomas A Caswell notifications@github.com
|
Maybe that was a problem, but it was not the only one. |
This needs a re-base again. |
I am going to rebase this against |
Leave it against master, we will cherry-pick the merge back to 1.5.x. On Sat, Oct 3, 2015 at 12:16 PM Gilles Marin notifications@github.com
|
Hi guys, |
@@ -65,7 +66,7 @@ def _apply_style(d, warn=True): | |||
mpl.rcParams.update(_remove_blacklisted_style_params(d, warn=warn)) | |||
|
|||
|
|||
def use(style): | |||
def use(styles): |
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.
bit concerned about the API break on changing the arg name.
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 agree, I did not think about this.
Then, shoud I just adapt to keep the same API?
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.
Yeah, just leave it as style
and accept the some-what dodge plural issues.
Allows to support cascading stylesheets directly from the matplorlibrc fixed an issue with depth > 1 added test getting parent styles + sample test styles fixed location of sample styles PEP8 fixes added import of stylesheets in setupext and test_only fixed stylesheet path in test_style other styles path fix other fix for styles path fixed an issue in style.use priority of styles passed added smaller functions for get_parents_styles function Fixed issues concerning parent styles importing other small functions to insert parent styles in the style list + small tweaks simplified the check of dictionnary like object using isinstance Few changes (some refactoring + docstring change) Using @tonysyu dictonnary flattening function to get children styles Added tests + dictionnary flattening fixes Docstring addition PEP8 fix pep8 fix removed style file imports needed for the now removed tests Fix for Py 2.6: some nose function did not exist
New rebase on top of master. |
Not sure why the tests failed, but doesn't seem related to my rebase. |
return parent_style | ||
|
||
|
||
def flatten_inheritance_dict(child_dict, parent_key, |
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.
Why leave this public?
|
||
|
||
def flatten_inheritance_dict(child_dict, parent_key, | ||
expand_parent=lambda x: x): |
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.
and why leave this with a default value like this?
That test has been flaky recently. There is some weird public vs private function things (there is a public function which is used in a private function which is called from a public function with is called from a private function which is used in |
This kind of got dropped. I'm also not 100% sure about the reason why someone would want this as an rcparam, nor has there been a user base clamouring for this. But please do re-open if I'm mistaken. |
Added a style RC parameter to be able to import styles from stylesheet or matplotlibrc.
You can call a parent stylesheet using the following syntax in your matplotlibrc or a stylesheet:
'style : chosen_style' if the style is in the library (built-in styles or a style put in your user config path
'style : path/to/style' to get a style from anywhere.
I also added a test to make sure we get the good rcParameters when calling parent styles. For that, I added sample stylesheets in the
sample_data parameter
, that form the same tree as the one seen in theget_style_parameters
function. It should cover every possible override possible.Priority order remark : When calling styles this way, the first ones will have the highest priority.
Todo: