Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed as not planned
Closed as not planned
Description
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
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