我有一个如下的数据帧:
import pandas as pd
import numpy as np
period0 = pd.date_range('1/1/2011', periods=50, freq='D')
period1 = pd.date_range('18/5/2012', periods=50, freq='D')
period2 = pd.date_range('7/11/2014', periods=50, freq='D')
df = pd.concat((pd.DataFrame(period0), pd.DataFrame(period1), pd.DataFrame(period2)), axis=0)
df['y'] = pd.DataFrame(np.random.rand(150,1))
这些日期和时段是任意选择的,以创建一些间隙和日期。你知道吗
当我尝试绘制数据帧时,matplotlib会在日期间隔之间自动绘制一条线:
plt.plot(df[0], df['y'])
我也试过dotplot
。但这并没有阻止绘图创建线条:
plt.plot(df[0], df['y'], ':')
我还发现了一个relevant question。不幸的是,它没有解决我的问题。你知道吗
那么,我该怎么办?你知道吗
如果无法修改现有索引,可以尝试:
您应该定义不希望被视为NaN的值:
https://matplotlib.org/examples/pylab_examples/nan_test.html
例如:
相关问题 更多 >
编程相关推荐