简体   繁体   中英

How can you set the x-axis in matplotlib?

I have data of shipping dates (1=Jan, 2=Feb ect..) and revenue corresponding to it in a pandas dataframe.

Data Frame Here

My code for the line graph that I am trying to make is:

finalhelp.plot(x='shippeddate',y='revenue',title='Revenue Per Month')

It returns a line graph like this linegraph

I tried to fix it by using the code

fig = finalhelp.plot(x='shippeddate',y='revenue',title='Revenue Per Month',yticks=([0,20000,40000,60000,80000,100000]), legend=False,)
fig.set_xticklabels(['','Jan','Feb','March','April','May','June','July','August','Sept','Oct','Nov','Dec'])

I would like to find a way to set each of the x axis to one of the corresponding months, right now it still returns only Jan-June.

It returns this image newlinegraph

You need to set_xticks and set_xticklabels :

fig.set_xticks(df['shippeddate'])
fig.set_xticklabels(['Jan','Feb','March','April','May','June','July','August','Sept','Oct','Nov','Dec'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM