0

I would like to make xtick show all months from November,2019 to February,2021. With the following code, xtick's interval in plot is 2 months.
How should I change it as 1 month interval?

I used mdate to fix it, but the output was just the same.

# create figure and axis objects with subplots()
fig,ax = plt.subplots()
# make a plot
ax.plot(df.Date, df.Close, color="yellow",)
# set x-axis label
ax.set_xlabel("date",fontsize=14)
ax.set_xticklabels(df.Date, Rotation=45) 
# set y-axis label
ax.set_ylabel("gold price",color="red",fontsize=14)

# twin object for two different y-axis on the sample plot
ax2=ax.twinx()

# make a plot with different y-axis using second axis object
ax2.plot(us_ncase.date,us_ncase.new_cases ,color="red")
ax2.set_ylabel("Covid New Case",color="blue",fontsize=14)
plt.show()
Cielo Kim
  • 21
  • 4
  • Please [edit] your question with the code *as text*. Screenshots of code are discouraged here. – BigBen Feb 12 '21 at 17:54
  • 3
    The answers to the following question should help: [How to change the datetime tick label frequency for matplotlib plots?](https://stackoverflow.com/questions/45704366/how-to-change-the-datetime-tick-label-frequency-for-matplotlib-plots) If they don't, you could then update your code with what you have tried. – Patrick FitzGerald Feb 14 '21 at 08:08

0 Answers0