. Advertisement .
..3..
. Advertisement .
..4..
I am new to python and searching the “fixedformatter should only be used together with fixedlocator” to understand it better. It seems it doesn’t work as expected when I used some suggestions before. Here is the command line I use:
def format_y_label_thousands(): # format y-axis tick labels formats
ax = plt.gca()
label_format = '{:,.0f}'
ax.set_yticklabels([label_format.format(x) for x in ax.get_yticks().tolist()])
def format_y_label_percent(): # format y-axis tick labels formats
ax = plt.gca()
label_format = '{:.1%}'
ax.set_yticklabels([label_format.format(x) for x in ax.get_yticks().tolist()])
The error I’m getting is below:
UserWarning: FixedFormatter should only be used together with FixedLocator
ax.set_yticklabels([label_format.format(x) for x in ax.get_yticks().tolist()])
Please give me the solution to this issue.
The cause:
After researching your problem for hours, I found that when you utilized an AutoLocator while changing the view or zooming, the labels frequently finished applying to the incorrect ticks. Therefore, this error happened.
Solution:
Let’s use FixedLocator to get rid of the warning (that is part of matplotlib.ticker). We have provided a code to plot three charts below. We use many formats for their axes. Although “set ticks” silences the warning, it alters the locations and labels of the real ticks (we spend a lot of time on finding that FixedLocator uses the same information but it still holds the original locations of ticks). To explore how each answer might impact the result, experiment with the x/ y’s.
THE FOLLOWING ARE THE OUTPUT CHARTS. There is a few unused lines of code as the one above (we simply collect the xticks or yticks and set them again), only makes our application noisier. The warning should be removed, in our opinion. The contributors who administer matplotlib have their reasons for maintaining the warning, though, if you check into some of the “bug reports” (from links on the comments above/below; the problem is not truly an error: it is an update that is causing some issues). MATPLOTLIB ANCIENT VERSION: The warning messages could be troublesome if you utilize your console to manage negative code outputs, like we do. Therefore, downgrading matplotlib to version 3.2.2 is a way to put off having to deal with the problem. Here is the command used to downgrade matplotlib in Anaconda, which we use to manage our Python packages:
Howerver, some of the listed versions might not be accessible. For example, in spite of appearance on matplotlib’s releases page, we were unable to install matplotlib 3.3.0: https://github.com/matplotlib/matplotlib/releases
FixedLocator is not required if someone arrives here using
axes.xaxis.set_ticklabels()
or yaxis equivalent. You can also avoid this warning by usingaxes.xaxis.set_ticks(values_list)
BEFOREaxes.xaxis.set_ticklabels(labels_list)
.