You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm seeing an inconsistency when I set the major tick locator and formatter in the "wrong" order, like clearing an axis does. I think it's happening because the tick locator is stored at least twice, and not all copies are being told when it changes.
The first copy is in the major ticker, axis.major.locator, and the second is in some types of tick formatters, like dates.AutoDateFormatter. Calling axis.set_major_locator() updates the copy in the ticker and the one in the current formatter, but calling axis.set_major_formatter()does not update the new formatter with the current locator. This allows the two to disagree if the locator is set before the formatter.
This example uses axis.clear() to illustrate the problem since that's what's tickling it for me. Internally, that method sets the locator and formatter to defaults, in the "wrong" order. This code should fail by assertion. Swapping the indicated lines causes it to succeed for the reasons given above.
importmatplotlib.datesasmdatesimportmatplotlib.pyplotaspltdefmain():
fig=plt.figure()
axes=fig.add_subplot(111)
loc=mdates.AutoDateLocator(interval_multiples=True)
fmt=mdates.AutoDateFormatter(loc)
setTicks(axes, loc, fmt)
axes.clear() # sets the locator, then the formattersetTicks(axes, loc, fmt)
defsetTicks(axes, loc, fmt):
axes.xaxis_date()
axes.xaxis.set_major_locator(loc) # swapping this line and...axes.xaxis.set_major_formatter(fmt) # ...this line "fixes" the assertion failurelocActual=axes.xaxis.get_major_locator()
fmtActual=axes.xaxis.get_major_formatter()
assertlocActualislocassertfmtActualisfmtassertfmtActual._locatorisloc# the assertion failure is hereif__name__=="__main__":
main()
I wouldn't expect the order those methods are called to matter. I'm on Red Hat Enterprise Linux 8.4, running Python 3.8.5 with matplotlib 3.3.2, but the current head commit looks unchanged in this area.
Not really knowing the code, my guess at a fix would be adding this at the bottom of axis._set_formatter().
formatter._set_locator(level.locator)
I haven't tried this though.
The text was updated successfully, but these errors were encountered:
I'm seeing an inconsistency when I set the major tick locator and formatter in the "wrong" order, like clearing an axis does. I think it's happening because the tick locator is stored at least twice, and not all copies are being told when it changes.
The first copy is in the major ticker, axis.major.locator, and the second is in some types of tick formatters, like dates.AutoDateFormatter. Calling
axis.set_major_locator()
updates the copy in the ticker and the one in the current formatter, but callingaxis.set_major_formatter()
does not update the new formatter with the current locator. This allows the two to disagree if the locator is set before the formatter.This example uses
axis.clear()
to illustrate the problem since that's what's tickling it for me. Internally, that method sets the locator and formatter to defaults, in the "wrong" order. This code should fail by assertion. Swapping the indicated lines causes it to succeed for the reasons given above.I wouldn't expect the order those methods are called to matter. I'm on Red Hat Enterprise Linux 8.4, running Python 3.8.5 with
matplotlib
3.3.2, but the current head commit looks unchanged in this area.Not really knowing the code, my guess at a fix would be adding this at the bottom of axis._set_formatter().
I haven't tried this though.
The text was updated successfully, but these errors were encountered: