多指标散点图

Multiindex scatter plot

假设我有以下数据:

data = {'Value': {('1', 1): 3.0,
('1', 2): 4.0,
('1', 3): 51.0,
('1', 4): 10.0,
('1', 5): 2.0,
('1', 6): 17.0,
('1', 7): 14.0,
('1', 8): 7.0,
('1', 9): 2.0,
('1', 10): 1.0}}
df=pd.DataFrame(data)

假设这代表一月份前十天的某些值。我想绘制这些数据,所以我使用:

df.plot()
plt.show()

现在,假设我有另一个数据集,其中包含这些日期的子集的值,这些日期的值略有不同但索引值相同:

df1 = df[df['Value']<10]
df1['Value'] = df1['Value']*2

我的问题是,如何在原始折线图上叠加此数据的散点图?

获取第一个图的轴句柄,然后重新索引 df1 以将数据与 df 相同的索引对齐,并使用 ax=ax.

绘制 df1
ax = df.plot()
df1.reindex(df.index).plot(marker='o',linestyle='none',color='g', ax=ax)

输出: