I am trying to plot price over date. But the density is too much so I want to use locator_params() to control it. My code is below.
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure
import matplotlib.dates as mdates
df = pd.read_csv(in_data)
y = df['Price']
x = df['DATE']
plt.plot(x, y)
plt.xlabel('Date')
plt.xlabel('Yield')
plt.title('test_plot')
plt.gcf().autofmt_xdate()
plt.locator_params(nbins=20)
I am trying to put only 20 dates on the plot. However, the plot pick the first 20 dates in x and put it on the plot, rather than pick every (total_number_of_date/20) date. Could you guys tell me what I missed here?
I also tried added in the following code but it won't help either.
plt.IndexLocator(base = 35, offset=0)
Thank you!