Skip to content

matplotlibrc parsing is inconsistent with matplotlibrc.template #9184

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

Closed
efiring opened this issue Sep 14, 2017 · 5 comments
Closed

matplotlibrc parsing is inconsistent with matplotlibrc.template #9184

efiring opened this issue Sep 14, 2017 · 5 comments
Milestone

Comments

@efiring
Copy link
Member

efiring commented Sep 14, 2017

matplotlib._rc_params_in_file looks for key : value pairs on a single line, but the matplotlibrc.template has a multiline entry for axes.prop_cycle. If you uncomment that entry in a matplotlibrc file, it will fail.

This was pointed out in an email to matplotlib-users on 9/13.

It applies to master (and the 2.1rc).

@efiring
Copy link
Member Author

efiring commented Sep 14, 2017

Here is the email from Emlyn Price:

Hi,

I have been trying to set up a custom color cycle in matplotlib using the matplotlibrc file. I have encountered a problem with the default matplotlibrc file provided with the installation from Arch llinux's package manager and the example provided in the online documentation at: https://matplotlib.org/users/customizing.html

When the lines controlling the axes.prop_cycle are uncommented:

axes.prop_cycle    : cycler('color',
                            ['1f77b4', 'ff7f0e', '2ca02c', 'd62728',
                              '9467bd', '8c564b', 'e377c2', '7f7f7f',
                              'bcbd22', '17becf'])


the following message is generated when I import matplotlib:

/usr/lib/python3.6/site-packages/matplotlib/__init__.py:1078: UserWarning: Illegal line #338
    "                            ['1f77b4', 'ff7f0e', '2ca02c', 'd62728',
"
    in file "/home/ejp/mpl_test/matplotlibrc"
  warnings.warn('Illegal %s' % error_details)
/usr/lib/python3.6/site-packages/matplotlib/__init__.py:1078: UserWarning: Illegal line #339
    "                              '9467bd', '8c564b', 'e377c2', '7f7f7f',
"
    in file "/home/ejp/mpl_test/matplotlibrc"
  warnings.warn('Illegal %s' % error_details)
/usr/lib/python3.6/site-packages/matplotlib/__init__.py:1078: UserWarning: Illegal line #340
    "                              'bcbd22', '17becf'])
"
    in file "/home/ejp/mpl_test/matplotlibrc"
  warnings.warn('Illegal %s' % error_details)
/usr/lib/python3.6/site-packages/matplotlib/__init__.py:1120: UserWarning: Bad val "cycler('color'," on line #337
    "axes.prop_cycle    : cycler('color',
"
    in file "/home/ejp/mpl_test/matplotlibrc"
    Key axes.prop_cycle: 'cycler('color',' is not a valid cycler construction: unexpected EOF while parsing (<string>, line 1)
  (val, error_details, msg))

The same error is generated if I import cycler using

import cycler

or

from cycler import cycler

I am using matplotlib 2.0.2 in python version 3.6.2 installed from the Arch Linux repositories.
The ouput of uname -a is :Linux tinker 4.12.12-1-ARCH #1 SMP PREEMPT Sun Sep 10 09:41:14 CEST 2017 x86_64 GNU/Linux

To reproduce:

Copy the default matplotlibrc
Uncomment the lines containing
axes.prop_cycle    : cycler('color',
                            ['1f77b4', 'ff7f0e', '2ca02c', 'd62728',
                              '9467bd', '8c564b', 'e377c2', '7f7f7f',
                              'bcbd22', '17becf'])
Run python in the directory containing the matplotlibrc file
Import matplotlib

Am I missing something obvious?
Thanks,
Emlyn

@jni
Copy link
Contributor

jni commented Sep 14, 2017

@efiring I found this as well during a matplotlib customization tutorial I ran, but then forgot to follow through with it. Would your suggested fix be to improve the parser or to fix the example matplotlibrc? If the latter, happy to submit a PR.

In the long term, it would be great if mpl applied some dogfooding here: the example should actually be loaded as the default style on launch. (Maybe?)

@efiring
Copy link
Member Author

efiring commented Sep 14, 2017

Improving the parser would be better--but so far it is needed only for this one entry, and I don't think it is trivial. I think that an immediate fix to the template would be worth doing, and simple enough to slip in before the actual 2.1 release. It's possible that longer term we might change the matplotlibrc handling in a more fundamental way, making it even less inviting to try to change the parsing right now.

So, "yes, please" to your PR offer.

@anntzer
Copy link
Contributor

anntzer commented Sep 14, 2017

If we want to fix the parser while keeping the matplotlibrc format (which, I've argued in other places, is not a great idea IMO -- just switching to Python expressions would make our life much simpler), the easiest would probably be to support explicit backslash line continuations.

WeatherGod pushed a commit that referenced this issue Sep 15, 2017
Otherwise the example is invalid because the matplotlibrc parser
doesn't understand multi-line commands. See #9184.
@tacaswell tacaswell added this to the 2.2 (next next feature release) milestone Sep 16, 2017
@anntzer
Copy link
Contributor

anntzer commented Sep 16, 2017

Closing as the issue of fixing the parser is already tracked by other issues e.g. #7089.

@anntzer anntzer closed this as completed Sep 16, 2017
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants