[英]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. 我在熊猫数据框中具有发货日期(1 = 1月,2 = 2月等)和与之相对应的收入的数据。
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 它返回了曲线图,这样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. 我想找到一种将每个x轴设置为相应月份之一的方法,现在它仍然只返回1月-6月。
It returns this image newlinegraph 它返回此图像换行图
You need to set_xticks
and set_xticklabels
: 您需要
set_xticks
和set_xticklabels
:
fig.set_xticks(df['shippeddate'])
fig.set_xticklabels(['Jan','Feb','March','April','May','June','July','August','Sept','Oct','Nov','Dec'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.