日期时间轴间距

编程入门 行业动态 更新时间:2024-10-28 13:18:29
本文介绍了日期时间轴间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个错误栏图,其中xaxis是datetime对象的列表。标准绘图方法将放置第一个和最后一个点,使其正好在图的边界框上。我想要偏移一半,以便清楚地看到第一点和最后一点。

I have an errorbar plot where the xaxis is a list of datetime objects. The standard plotting method will put the first and last point so that they are right on the bounding box of the plot. I would like to offset by a half tick so that the first and last point can be seen clearly.

ax.axis(xmin=-0.5,xmax=len(dates)-0.5)

由于明显的原因不起作用。在没有硬编码任何日期的情况下,可以做到这一点是件好事。

does not work for obvious reasons. It would be nice to be able to do this without hardcoding any dates.

以下内容将会产生一个十分,但只能看到8的情节。 p>

The following will produce a plot which has ten points but you can really only see 8.

import datetime import matplotlib.pyplot as plt dates = [datetime.date(2002, 3, 11) - datetime.timedelta(days=x) for x in range(0, 10)] yvalues = [2, 4, 1,7,9,2, 4, 1,7,9] errorvalues = [0.4, 0.1, 0.3,0.4, 0.1,.4, 0.1, 0.3,0.4, 0.1] fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.errorbar(dates,yvalues,yerr=errorvalues,fmt='.') fig.autofmt_xdate() plt.show()

推荐答案

可以使用边距设置间距)

You can set spacing with margins()

import datetime import matplotlib.pyplot as plt dates = [datetime.date(2002, 3, 11) - datetime.timedelta(days=x) for x in range(0, 10)] yvalues = [2, 4, 1,7,9,2, 4, 1,7,9] errorvalues = [0.4, 0.1, 0.3,0.4, 0.1,.4, 0.1, 0.3,0.4, 0.1] fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.errorbar(dates,yvalues,yerr=errorvalues,fmt='.') ax.margins(x=0.05) fig.autofmt_xdate() plt.show()

更多推荐

日期时间轴间距

本文发布于:2023-11-22 09:33:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616902.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:间距   日期   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!