I have a simple bar chart with a line chart over it.
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()
When I run it, it works fine. But I get this warning:
"""
<ipython-input-65-9b40369b760b>:15: UserWarning: FixedFormatter should only be used together with
FixedLocator
ax1.set_xticklabels(x, rotation="vertical", size=12)
"""
All I need to know is how to avoid this warning.
It seems to be a bug with the latest version. You can read more about it here.
Their solution seems to be to set xticks before you set the lables, so for you example, we just add this before your labels:
ax1.set_xticks(x)
ax1.set_xticklabels(x, rotation="vertical", size=12)
The warning is removed on my side then at least.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With