【问题标题】:FixedFormatter_shoul_only_be_used_together_with_FixedLocator: How to deal with this warning in matplotlib?FixedFormatter_shoul_only_be_used_together_with_FixedLocator:如何在 matplotlib 中处理这个警告?
【发布时间】:2020-09-04 21:24:39
【问题描述】:

我有一个简单的条形图,上面有一个折线图。

import numpy as np
import matplotlib.pyplot as plt

x = np.array(["one", "two", "three", "four"])
a = np.array([1, 2, 3, 4])
b = np.array([2, 4, 3, 1])

fig, ax1 = plt.subplots()

ax2 = ax1.twinx()
ax1.bar(x, a, color="g")
ax2.plot(x, b, color="r")

# Problem is here.
ax1.set_xticklabels(x, rotation="vertical", size=12)

plt.show()

当我运行它时,它运行良好。但我收到了这个警告:

"""
<ipython-input-65-9b40369b760b>:15: UserWarning: FixedFormatter should only be used together with 
FixedLocator
  ax1.set_xticklabels(x, rotation="vertical", size=12)
"""

我只需要知道如何避免这个警告。

【问题讨论】:

    标签: python matplotlib warnings


    【解决方案1】:

    这似乎是最新版本的一个错误。你可以阅读更多关于它的信息here

    他们的解决方案似乎是在你设置标签之前设置xticks,所以对于你来说,我们只是在你的标签之前添加这个:

    ax1.set_xticks(x)
    ax1.set_xticklabels(x, rotation="vertical", size=12)
    

    至少我这边的警告被删除了。

    【讨论】:

      猜你喜欢
      • 2013-03-30
      • 2022-08-19
      • 1970-01-01
      • 2017-10-18
      • 1970-01-01
      • 2020-07-21
      • 1970-01-01
      • 2021-09-30
      • 2018-04-13
      相关资源
      最近更新 更多