我有一個簡單的條形圖,上面有一個折線圖。import numpy as npimport matplotlib.pyplot as pltx = 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)"""我需要知道的是如何避免這個警告。
1 回答

jeck貓
TA貢獻1909條經驗 獲得超7個贊
這似乎是最新版本的一個錯誤。
他們的解決方案似乎是xticks
在設置標簽之前進行設置,因此對于您來說,我們只需在標簽之前添加以下內容:
ax1.set_xticks(x) ax1.set_xticklabels(x,?rotation="vertical",?size=12)
至少我這邊的警告被刪除了。
添加回答
舉報
0/150
提交
取消