简体   繁体   中英

How can I scale the gap between x-axis ticks which are dates?

I have a bar graph which has datetimes on the x-axis. How can I add gaps between x-ticks with respect to the timedelta between each neighbour ticks? The solution does not have to be a bargraph, I can use any kind of graph which satisfies my problem.

在此处输入图像描述

For these kind of problems you may set x axis as date field. This will fill in na dates and leave gaps accordingly which is helpful to analyze time series and things like monthly spending and it's quite easy to do. Following code snipper should help.

ax = plt.subplot(111)
ax.bar(x, y, width=10)
ax.xaxis_date()

plt.show()

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