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
Make it possible to add mpl.rcParams to itself or deepcopy #2555
Conversation
I think it would actually make sense to add and constructor to RcParams which would remove all deprecated params. The validators would still be there so they could be added, but they wouldn't be there if someone pokes into mpl.rcParams. |
also: 'tk.pythoninspect' should probably be added to |
Ok, two build failues: On 2.6
-> assert_raises(9 can only be used on 2.7+ -> http://stackoverflow.com/questions/17585207/python-unittest-assetraises and on 3.x:
|
Added changes to let the tests pass:
|
Before it was not possible to set all rcParams to mpl.rcParams or use copy.deepcopy on mpl.rcParams. There were two problems: 1. validate_bool_maybe_none(None) was raising ValueError -> fixed by accepting this value 2. svg.embed_char_paths was deprecated by svg.fonttype but both have different valid values (bool vs strings). -> fixed by adding a "value translation" lambda to deprecatedmap which translates the boolean values to the string values of svg.fonttype. Also changed all validators, which accept None to check strings without case ("none" vs "None"). Test for this: mpl.tests.test_rcparams.test_Bug_2543() Closes: matplotlib#2543
What's the use case for this? If it's to create a temporary context for parameters, would it be better to use |
I had to work around this when I implemented theming for yhat/ggpy#75. One of the problems was that In another implementation idea I tried to copy the rcParam dict directly (without copying it to a dict), but that resulted in the problem with deepcopy when adding another geom/... to the ggplot object. |
I found it very strange, that the deprecated keys are still added to rcParams. Wouldn't it make sense to "forget" deprecated keys in the default rcParams dict? Edit: The obsolete defaults are in rcsetup.py -> defaultParams. They get added to each rcParams: ret = RcParams([(key, default) for key, (default, _) in \
six.iteritems(defaultParams)]) The easiest thing would be to add a |
I think this should be merged, it fixes a bug. I have restarted the tests to make sure they still pass. |
@@ -92,6 +95,43 @@ def test_RcParams_class(): | |||
assert ['font.cursive', 'font.size'] == sorted(rc.find_all('i[vz]').keys()) | |||
assert ['font.family'] == list(six.iterkeys(rc.find_all('family'))) | |||
|
|||
def test_Bug_2543(): |
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 this name could be better - as a reader I don't know what bug 5243 is, so describing the problem in the name would be a better approach IMHO.
Make it possible to add mpl.rcParams to itself or deepcopy
Before it was not possible to set all rcParams to mpl.rcParams or use
copy.deepcopy on mpl.rcParams.
There were two problems:
-> fixed by accepting this value
different valid values (bool vs strings).
-> fixed by adding a "value translation" lambda to _deprecated_map
which translates the boolean values to the string values of
svg.fonttype.
[EDIT]
Also changed all validators, which accept None to check strings
without case ("none" vs "None").
removed rcPrams.update method because there were too many warnings when using rc_context()
[/EDIT]
Also added a new test for this: mpl.tests.test_rcparams.test_Bug_2543()
I wasn't able to compile matplotlib under my windows environment and only did the changes in my original installed mathplot and the test in a ipyhton notebook. So please check and test before merging...
Closes: #2543