0
问题是绘制日期不均匀分布的直线。使用系列值数据可以修正曲线问题,但会丢失时间轴(日期)。有没有办法来解决这个问题?绘制大熊猫系列线变成曲线
编辑:为什么不直接映射到X轴刻度日期:
0 -> 2017-02-17,
1 -> 2017-02-20,
... ?
现在有似乎是橙色线12个蜱,但只有8个数据点。
import pandas as pd
import matplotlib.pyplot as plt
def straight_line(index):
y = [3 + 2*x for x in range(len(index))]
zserie = pd.Series(y, index=index)
return zserie
if __name__ == '__main__':
start = '2017-02-10'
end = '2017-02-17'
index = pd.date_range(start,end)
index1 = pd.DatetimeIndex(['2017-02-17', '2017-02-20', '2017-02-21', '2017-02-22',
'2017-02-23', '2017-02-24', '2017-02-27', '2017-02-28',],
dtype='datetime64[ns]', name='pvm', freq=None)
plt.figure(1, figsize=(8, 4))
zs = straight_line(index)
zs.plot()
zs = straight_line(index1)
zs.plot()
plt.figure(2, figsize=(8, 4))
zs = straight_line(index1)
plt.plot(zs.values)
您是否试图创建日期间不均匀间距的直线(x轴),或者您是否试图使日期值像分类值一样工作? – Craig
第一块情节中的橙色线似乎正是您正在寻找的情节。它有什么问题? – ImportanceOfBeingErnest
要得到一条直线,您必须调整x轴以与y轴相同的速率进行调整。这对于绘制彼此不同距离的日期并不适用。为什么你需要图表对于数据是一条直线? – Aklys