FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

matplotlibrc validates some parameters wrongly · Issue #16583 · matplotlib/matplotlib · GitHub

Repository navigation

matplotlibrc validates some parameters wrongly #16583

Closed

Description

Bug report

Bug summary

I would like to set how xticks are aligned. There is the ha (for horizontalalignment) parameter which controls this with the possible values 'left', 'center' and 'right'.
To globally set this parameter, I tried to set xtick.alignment in my .matplotlibrc config file.
However when setting it to 'left', I get an error (when I start ipython):

Bad val 'right' on line #27
"xtick.alignment : right
"
in file "/home/moritz/.config/matplotlib/matplotlibrc"
Key xtick.alignment: Unrecognized alignment string 'right': valid strings are ['center', 'top', 'bottom', 'baseline', 'center_baseline']

So I tried to set it to 'bottom' (to see what happens) and plotted a simple curve (see code below), but then I got a ValueError:

...
/usr/lib/python3.8/site-packages/matplotlib/text.py in init(self, x, y, text, color, verticalalignment, horizontalalignment, multialignment, fontproperties, rotation, linespacing, rotation_mode, usetex, wrap, **kwargs)
156 self.set_wrap(wrap)
157 self.set_verticalalignment(verticalalignment)
--> 158 self.set_horizontalalignment(horizontalalignment)
159 self._multialignment = multialignment
160 self._rotation = rotation

/usr/lib/python3.8/site-packages/matplotlib/text.py in set_horizontalalignment(self, align)
940 align : {'center', 'right', 'left'}
941 """
--> 942 cbook._check_in_list(['center', 'right', 'left'], align=align)
943 self._horizontalalignment = align
944 self.stale = True

/usr/lib/python3.8/site-packages/matplotlib/cbook/init.py in _check_in_list(values, **kwargs)
2189 for k, v in kwargs.items():
2190 if v not in values:
-> 2191 raise ValueError(
2192 "{!r} is not a valid value for {}; supported values are {}"
2193 .format(v, k, ', '.join(map(repr, values))))

ValueError: 'top' is not a valid value for align; supported values are 'center', 'right', 'left'

In conclusion, the matplotlibrc validation for the xtick.alignment parameter is bogus.

Code for reproduction

Either

xtick.alignment : top

Or

xtick.alignment : left

in .matplotlibrc

matplotlib.pyplot.plot([1,2,3], [5,3,9])

for provoking the ValueError (see above

Matplotlib version

  • Operating system: Arch Linux
  • Matplotlib version: 3.1.3
  • Matplotlib backend (print(matplotlib.get_backend())):
  • Python version: 3.8.1

Activity

  1. ImportanceOfBeingErnest commented on Feb 27, 2020

    Member

    It looks like #7970 headed out to introduce a vertical-alignment parameter to y-ticklabels only. But then a rework of that in #8081 introduceda parameter for the vertical alignment for y-ticklabels and the horizontal alignment for x-ticklabels - except that validation is still for vertical-alignment only.

    I suppose the easy fix is to just replace

    'xtick.alignment': ['center',
    ['center', 'top', 'bottom', 'baseline', 'center_baseline']],

    Such fix has to go on top of #16483 which is milestoned for 3.3, but given that the problem hasn't bothered anyone since 2.0.1, it might be ok to not hassle about backporting.

  2. MuhammadFarooq1234 commented on Mar 3, 2020

    Contributor

    If no one is working on this, I would like take a shot at it.

  3. timhoffm commented on Mar 3, 2020

    Member

    Go for it.

  4. MuhammadFarooq1234 commented on Mar 6, 2020

    Contributor

    Thanks, I've updated the rcsetup.py like so:

    'xtick.alignment': ['center', ['center', 'right', 'left']]

    and validated it works. As for unit testing, is there a way to test this other than using image comparison tests? Something like a "get_tick_alignment" of the axis or something like that?

  5. efiring commented on May 6, 2020

    Member

    Closed by #16727.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL