FixFormatter_shoul_only_be_used_together_with

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


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)

"""

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


慕仙森
浏览 128回答 1
1回答

jeck猫

这似乎是最新版本的一个错误。他们的解决方案似乎是xticks在设置标签之前进行设置,因此对于您来说,我们只需在标签之前添加以下内容:ax1.set_xticks(x) ax1.set_xticklabels(x, rotation="vertical", size=12)至少我这边的警告被删除了。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python