You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
custom style sheet: format dates with new line character #15813
In my custom matplotlib style sheet, I want to format the dates in such a way that includes a new line character, i.e., %b %d\n%H:%M. But matplotlib will not recognize the new line character and instead prints \n as text on my figure.
# If applicable, paste the console output here
#
#
Expected outcome
I can get the desired outcome if I use the manual method to change the date formats directly in my code, but I would rather avoid repeating these lines of code in all my plotting scripts. That is why I want to use the style sheet to do this.
This is currently not possible because the parser interprets values as literal strings and thus the backslash is an actual backslash.
In [2]: plt.rcParams['date.autoformatter.hour']
Out[2]: '%b %d\\n%H:%M'
One could do val.decode('unicode_escape') but that would be an API change.
We could however optionally allow string quotes date.autoformatter.hour : "%b %d\n%H:%M" and only text in quotes will be unescaped. That would keep backward-compatibility. It's also consistent with the way YAML handles strings. 😄
We could however optionally allow string quotes date.autoformatter.hour : "%b %d\n%H:%M" and only text in quotes will be unescaped. That would keep backward-compatibility.
I don't think this keeps backcompat? I'd say the breakage is unlikely to matter in practice, but both adding support for quotes and adding support for escapes break backcompat to similar extents...
Perhaps a better solution would be to just use a different syntax to mark "new" entries, e.g.
date.formatter.hour = "..."
i.e. the equals sign (rather than colon) says that what comes after is a python literal (which we should just load using ast.literal_eval).
Theoretically, it's backward compatible, but only if somebody had used string-quoting before and meaning the quotes literally. The likelyhood lf that is small, and I'd be willing to risk that. Since we will only parse escapes in quotes the breakage probability of that is ɛ².
I'm not convinced of making a semantic difference with = vs. :. This is a good recipe to confuse users.
I'd also be open towards making the config YAML, which AFAICS the current config is a subset of (PyYAML has become active again for what it's worth).
I'm alternatively not completely opposed to a python config, but would need a little more convincing that's a benefit worth introducing a large incompatibility (or us maintaining two formats, respectively.
If we choose to move to yaml (ugh) or python, the easiest is likely to just make the config files matplotlibrc.yml or matplotlibrc.py respectively, which will allow supporting both formats during the transition period without any guessing/incompatibility (and even after we drop (perhaps) support for old-style matplotlibrc, people can just keep both formats around if they want backcompat with old matplotlibs).
(I agree there's still some maintenance cost, but the python-format loader would be pretty trivial...)
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
changed the title [-]matplotlib cutsom style sheet: format dates with new line character[/-][+]custom style sheet: format dates with new line character[/+]on Oct 13, 2026
Activity
timhoffm commentedon Dec 2, 2019
This is currently not possible because the parser interprets values as literal strings and thus the backslash is an actual backslash.
One could do
val.decode('unicode_escape')but that would be an API change.We could however optionally allow string quotes
date.autoformatter.hour : "%b %d\n%H:%M"and only text in quotes will be unescaped. That would keep backward-compatibility. It's also consistent with the way YAML handles strings. 😄jklymak commentedon Dec 3, 2019
That proposal seems reasonable to me
anntzer commentedon Jan 25, 2021
I don't think this keeps backcompat? I'd say the breakage is unlikely to matter in practice, but both adding support for quotes and adding support for escapes break backcompat to similar extents...
Perhaps a better solution would be to just use a different syntax to mark "new" entries, e.g.
i.e. the equals sign (rather than colon) says that what comes after is a python literal (which we should just load using
ast.literal_eval).timhoffm commentedon Jan 26, 2021
Theoretically, it's backward compatible, but only if somebody had used string-quoting before and meaning the quotes literally. The likelyhood lf that is small, and I'd be willing to risk that. Since we will only parse escapes in quotes the breakage probability of that is ɛ².
I'm not convinced of making a semantic difference with
=vs.:. This is a good recipe to confuse users.I'd also be open towards making the config YAML, which AFAICS the current config is a subset of (PyYAML has become active again for what it's worth).
I'm alternatively not completely opposed to a python config, but would need a little more convincing that's a benefit worth introducing a large incompatibility (or us maintaining two formats, respectively.
anntzer commentedon Jan 26, 2021
If we choose to move to yaml (ugh) or python, the easiest is likely to just make the config files
matplotlibrc.ymlormatplotlibrc.pyrespectively, which will allow supporting both formats during the transition period without any guessing/incompatibility (and even after we drop (perhaps) support for old-style matplotlibrc, people can just keep both formats around if they want backcompat with old matplotlibs).(I agree there's still some maintenance cost, but the python-format loader would be pretty trivial...)
github-actions commentedon Jun 30, 2023
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
QuLogic commentedon Jun 30, 2023
Quoted strings were added in #22589. @timhoffm intended to add support for backslash escapes, but it doesn't look like that has been implemented yet.
github-actions commentedon Oct 5, 2026
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
timhoffm commentedon Oct 5, 2026
Nowadays, a format alternative could be TOML. I’d rather adopt a standard file format than bike shedding a proprietary one.
[-]matplotlib cutsom style sheet: format dates with new line character[/-][+]custom style sheet: format dates with new line character[/+]