単純な棒グラフとその上に折れ線グラフがあります。
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)
"""
私が知る必要があるのは、この警告を回避する方法だけです。
------------------------
最新バージョンのバグのようです。詳細については、こちらをご覧ください。
彼らの解決策は、ラベルを設定する前に xticks を設定することのようです。そのため、たとえば、ラベルの前にこれを追加するだけです。
ax1.set_xticks(x)
ax1.set_xticklabels(x, rotation="vertical", size=12)
これで、少なくとも私の側では警告が削除されました。
0