Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]: inconsistent results when formatting ticklabels by get_text() in time axis #26791

Closed as not planned
@stevenlis

Description

@stevenlis

Bug summary

I'm trying to format ticklabels based on text on a time x axis.I have been experiencing inconsistent results with various formatters.

Code for reproduction

importpandasaspdimportnumpyasnpfromdatetimeimportdateimportmatplotlib.pyplotaspltfrommatplotlib.datesimportMonthLocatorfrommatplotlib.datesimportConciseDateFormatterxs= [pd.date_range(f'{y}-07-01','2021-12-31',freq='M')foryinrange(2016,2019)]ys= [np.random.rand(len(x))forxinxs]fig,axs=plt.subplots(3,1,figsize=(10,8))forax,x,yinzip(axs,xs,ys):ax.plot(x,y)locator=MonthLocator((1,4,7,10))ax.xaxis.set_major_locator(locator)ax.xaxis.set_major_formatter(ConciseDateFormatter(locator))fortextinax.get_xaxis().get_ticklabels():# print(text.get_text())iftext.get_text().startswith('20'):text.set_fontsize(10)else:text.set_fontsize(5)ax.set_xlim(date(2016,7,1))

Actual outcome

ed619ab1-d916-4d40-ab27-61d8adedeee8

If you print theget_text() function, all the texts appear to be fine. However, for unknown reasons, certain texts are not picked by theset_fontsize() method.

Expected outcome

All the "20YY" will be set to fontsize 10

Additional information

No response

Operating system

OS/X

Matplotlib Version

3.7.1

Matplotlib Backend

No response

Python version

3.10

Jupyter version

No response

Installation

None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp