Skip to content

pyplot.xticks(): Font property specification is not effective except 1st tick label. #18922

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
AIWolfSharp opened this issue Nov 10, 2020 · 1 comment
Milestone

Comments

@AIWolfSharp
Copy link

Bug report

Bug summary

When I try to specity the font properties for x-tick's labels via **kwargs of pyplot.xtics(), the specification is not effective except 1st tick label.

Code for reproduction

from matplotlib import pyplot
from matplotlib.font_manager import FontProperties
pyplot.subplots(figsize=(1, 1), dpi=180)
fp = FontProperties(fname='/usr/share/fonts/ipa-pgothic/ipagp.ttf', size=6)
pyplot.xticks([1, 2], ["自分", "他人"], fontproperties=fp)

Actual outcome

スクリーンショット 2020-11-10 13-37-49

I found this comes from that specified font property is poped (see line 5 in code snippet below) from **kwargs in the function update in text.py, so the font property for 2nd tick label isn't specified any more.

    def update(self, kwargs):
        # docstring inherited
        sentinel = object()  # bbox can be None, so use another sentinel.
        # Update fontproperties first, as it has lowest priority.
        fontproperties = kwargs.pop("fontproperties", sentinel)
        if fontproperties is not sentinel:
            self.set_fontproperties(fontproperties)
        # Update bbox last, as it depends on font properties.
        bbox = kwargs.pop("bbox", sentinel)
        super().update(kwargs)
        if bbox is not sentinel:
            self.set_bbox(bbox)

When I experimentally change pop to get in the line, the plot is what I expected, like below.

Expected outcome
スクリーンショット 2020-11-10 13-40-46

Matplotlib version

  • Operating system:Fedora 32
  • Matplotlib version: 3.3.2
  • Matplotlib backend (print(matplotlib.get_backend())):Qt5Agg
  • Python version:3.8.6
@anntzer
Copy link
Contributor

anntzer commented Nov 10, 2020

AFIACT this was recently fixed by #18839. Thanks for the report.

@anntzer anntzer closed this as completed Nov 10, 2020
@anntzer anntzer added this to the v3.3.3 milestone Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants