I am trying to plot average temperatures of 3 months (January, February and December 2017) with x being each day of the month (type of data is datetime64[ns]). the number of x is 90 so I have 90 dates. Below is my code:
import matplotlib.pyplot as plt
from datetime import datetime
from matplotlib import dates as mpl_dates
date_format=mpl_dates.DateFormatter('%B')
#convert data to datetime.objects
x_dates.loc[:,["YEAR","DAY","MONTH"]]=x_dates.loc[:,["YEAR","DAY","MONTH"]]
x_dates1=pd.to_datetime(x_dates)
x_dates1=pd.DataFrame({"DATE":x_dates1}
#take the mean temperatures
ymean_winter=np.array(Winter["TEMP"])
#create and format figure
fig=plt.figure()
ax=fig.add_subplot(111)
ax.plot_date(x_dates1['DATE'],ymean_winter,linestyle='solid')
fig.autofmt_xdate()
plt.gca().xaxis.set_major_formatter(date_format)
plt.show()
Once I code the above I get the below:
Average temperature in Winter 2017
The problem is that I get this interval which I do not wish to have (March 2017 to November 2017). If I convert the dates to strings I don't have the issue but then I face the issue of either removing the x-ticks as I have too many x-ticks that they overlap each other and I can't discern the dates or enlarge the figure like fig=plt.figure(figsize=(35,35)) to be able to see each x point.
How can I remove the empty space?