Skip to content

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

Closed
@AIWolfSharp

Description

@AIWolfSharp

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions