UserWarning: FixedFormatter should only be used together with FixedLocator ax.set_xticklabels([''] + list(jieba.cut(input_sentence)) + ['<EOS>'], rotation=90)
时间: 2024-01-26 22:02:42 浏览: 138
UserWarning: FixedFormatter should only be used together with FixedLocator
This warning message indicates that the `set_xticklabels` method on an axis object is being used with a list of tick labels that does not match the locations of the actual ticks on the plot. This can result in unexpected or incorrect labeling of the plot.
The code `ax.set_xticklabels([''] + list(jieba.cut(input_sentence)) + ['<EOS>'], rotation=90)` is attempting to set the tick labels on the x-axis of a plot represented by the `ax` object. The list being passed as an argument to `set_xticklabels` includes an empty string followed by the result of applying the `cut` method from the `jieba` library to the `input_sentence` variable, and then appending the string `"<EOS>"`. The `rotation` argument is used to rotate the tick labels by 90 degrees.
To fix the warning message, it is necessary to ensure that the list of tick labels passed to `set_xticklabels` is of the same length as the number of actual ticks on the axis. One possible way to do this is to use the `set_xticks` method to explicitly set the locations of the ticks before setting the tick labels. For example:
```
ax.set_xticks(range(len(list(jieba.cut(input_sentence))) + 2))
ax.set_xticklabels([''] + list(jieba.cut(input_sentence)) + ['<EOS>'], rotation=90)
```
阅读全文