puneet
puneet

Reputation: 65

Formatting X axis labels Pandas time series plot

I am trying to plot a multiple time series dataframe in pandas. The time series is a 1 year daily points of length 365. The figure is coming alright but I want to suppress the year tick showing on the x axis.enter image description here

I want to suppress the 1950 label showing in the left corner of x axis. Can anybody suggest something on this? My code

dates = pandas.date_range('1950-01-01', '1950-12-31', freq='D')

data_to_plot12 = pandas.DataFrame(data=data_array,    # values
             index=homo_regions)    # 1st column as index


dataframe1 = pandas.DataFrame.transpose(data_to_plot12)
dataframe1.index = dates

ax = dataframe1.plot(lw=1.5, marker='.', markersize=2, title='PRECT time series PI Slb Ocn CNTRL 60 years')

ax.set(xlabel="Months", ylabel="PRECT (mm/day)")

fig_name = 'dataframe1.pdf'

plt.savefig(fig_name) 

Upvotes: 2

Views: 2037

Answers (1)

daryl
daryl

Reputation: 1200

You should be able to specify the xaxis major formatter like so

import matplotlib.dates as mdates
...
ax.xaxis.set_major_formatter(mdates.DateFormatter('%b'))

Upvotes: 2

Related Questions