为什么 matplotlib 不能在同一张图上绘制多条线?
Why matplotlib cannot plot multiple lines on the same graph?
我正在使用一个使用 jupyter 作为研究环境的在线回测平台 Quantconnect。
我有以下代码:
fig, ax = plt.subplots()
expiry_range = [180, 360]#, 540, 720]
for upper in expiry_range:
data = getAllOptionChains(symbols, -200, 200, upper-30, upper, datetime(2020, 1, 16, 10, 10), datetime(2020, 1, 16, 10, 11))
clean = data[data['S/E'] <1.2]
clean = clean.sort_values('S/E')
params, params_covariance = curve_fit(func,np.asarray(clean['S/E']).astype(np.float64), np.asarray(clean['W/E']).astype(np.float64))
#ax.scatter(np.asarray(clean['S/E']).astype(np.float64), np.asarray(clean['W/E']).astype(np.float64))
ax.plot(np.asarray(clean['S/E']).astype(np.float64), func(np.asarray(clean['S/E']).astype(np.float64), params[0], params[1]))
我试图在同一张图上绘制 2 条线。但我只能在情节中看到一行。我做错了什么?
这是我得到的剧情
数据样本clean
expiry symbol W/E S/E
26 2020-06-19 UVXY XFH59VEMBEQU|UVXY 2T 0.000864865 0.0577838
24 2020-06-19 UVXY XFH59UN03NNQ|UVXY 2T 0.000277778 0.0593889
23 2020-06-19 UVXY XFH59VCYS292|UVXY 2T 0.000914286 0.0610857
21 2020-06-19 UVXY XFH59UMU5BLY|UVXY 2T 0.00635294 0.0628824
20 2020-06-19 UVXY XFH59VBB8PRA|UVXY 2T 0.00545455 0.0647879
18 2020-06-19 UVXY XFH59UMO6ZK6|UVXY 2T 0.0046875 0.0668125
17 2020-06-19 UVXY XFH59V9NPD9I|UVXY 2T 0.00483871 0.0689677
15 2020-06-19 UVXY XFH59UMI8NIE|UVXY 2T 0.000933333 0.0712667
14 2020-06-19 UVXY XFH59V8060RQ|UVXY 2T 0.00344828 0.0737241
12 2020-06-19 UVXY XFH59UMCABGM|UVXY 2T 0.00535714 0.0763571
11 2020-06-19 UVXY XFH59V6CMO9Y|UVXY 2T 0.00555556 0.0791852
9 2020-06-19 UVXY XFH59UM6BZEU|UVXY 2T 0.00384615 0.0822308
8 2020-06-19 UVXY XFH59V4P3BS6|UVXY 2T 0.006 0.08552
6 2020-06-19 UVXY XFH59UM0DND2|UVXY 2T 0.00416667 0.0890833
5 2020-06-19 UVXY XFH59V31JZAE|UVXY 2T 0.00156522 0.0929565
3 2020-06-19 UVXY XFH59ULUFBBA|UVXY 2T 0.00454545 0.0971818
2 2020-06-19 UVXY XFH59V1E0MSM|UVXY 2T 0.00104762 0.10181
0 2020-06-19 UVXY XFH59UK6Y3ZA|UVXY 2T 0.00395 0.1069
64 2020-06-19 UVXY XFH59UZQHAAU|UVXY 2T 0.00789474 0.112526
62 2020-06-19 UVXY XFH59ULIIN7Q|UVXY 2T 0.00833333 0.118778
61 2020-06-19 UVXY XFH59UY2XXT2|UVXY 2T 0.00588235 0.125765
59 2020-06-19 UVXY XFH59ULCKB5Y|UVXY 2T 0.00925 0.133625
58 2020-06-19 UVXY XFH59UWFELBA|UVXY 2T 0.00473333 0.142533
56 2020-06-19 UVXY XFH59UL6LZ46|UVXY 2T 0.00507143 0.152714
55 2020-06-19 UVXY XFH59UURV8TI|UVXY 2T 0.00584615 0.164462
53 2020-06-19 UVXY XFH59UL0NN2E|UVXY 2T 0.00533333 0.178167
17 2020-06-19 I XFH59UQH2JJA|I 2T 0.0025641 0.181795
尝试在 for loop
外写 plt.show()
以显示所有行
我正在使用一个使用 jupyter 作为研究环境的在线回测平台 Quantconnect。
我有以下代码:
fig, ax = plt.subplots()
expiry_range = [180, 360]#, 540, 720]
for upper in expiry_range:
data = getAllOptionChains(symbols, -200, 200, upper-30, upper, datetime(2020, 1, 16, 10, 10), datetime(2020, 1, 16, 10, 11))
clean = data[data['S/E'] <1.2]
clean = clean.sort_values('S/E')
params, params_covariance = curve_fit(func,np.asarray(clean['S/E']).astype(np.float64), np.asarray(clean['W/E']).astype(np.float64))
#ax.scatter(np.asarray(clean['S/E']).astype(np.float64), np.asarray(clean['W/E']).astype(np.float64))
ax.plot(np.asarray(clean['S/E']).astype(np.float64), func(np.asarray(clean['S/E']).astype(np.float64), params[0], params[1]))
我试图在同一张图上绘制 2 条线。但我只能在情节中看到一行。我做错了什么?
这是我得到的剧情
数据样本clean
expiry symbol W/E S/E
26 2020-06-19 UVXY XFH59VEMBEQU|UVXY 2T 0.000864865 0.0577838
24 2020-06-19 UVXY XFH59UN03NNQ|UVXY 2T 0.000277778 0.0593889
23 2020-06-19 UVXY XFH59VCYS292|UVXY 2T 0.000914286 0.0610857
21 2020-06-19 UVXY XFH59UMU5BLY|UVXY 2T 0.00635294 0.0628824
20 2020-06-19 UVXY XFH59VBB8PRA|UVXY 2T 0.00545455 0.0647879
18 2020-06-19 UVXY XFH59UMO6ZK6|UVXY 2T 0.0046875 0.0668125
17 2020-06-19 UVXY XFH59V9NPD9I|UVXY 2T 0.00483871 0.0689677
15 2020-06-19 UVXY XFH59UMI8NIE|UVXY 2T 0.000933333 0.0712667
14 2020-06-19 UVXY XFH59V8060RQ|UVXY 2T 0.00344828 0.0737241
12 2020-06-19 UVXY XFH59UMCABGM|UVXY 2T 0.00535714 0.0763571
11 2020-06-19 UVXY XFH59V6CMO9Y|UVXY 2T 0.00555556 0.0791852
9 2020-06-19 UVXY XFH59UM6BZEU|UVXY 2T 0.00384615 0.0822308
8 2020-06-19 UVXY XFH59V4P3BS6|UVXY 2T 0.006 0.08552
6 2020-06-19 UVXY XFH59UM0DND2|UVXY 2T 0.00416667 0.0890833
5 2020-06-19 UVXY XFH59V31JZAE|UVXY 2T 0.00156522 0.0929565
3 2020-06-19 UVXY XFH59ULUFBBA|UVXY 2T 0.00454545 0.0971818
2 2020-06-19 UVXY XFH59V1E0MSM|UVXY 2T 0.00104762 0.10181
0 2020-06-19 UVXY XFH59UK6Y3ZA|UVXY 2T 0.00395 0.1069
64 2020-06-19 UVXY XFH59UZQHAAU|UVXY 2T 0.00789474 0.112526
62 2020-06-19 UVXY XFH59ULIIN7Q|UVXY 2T 0.00833333 0.118778
61 2020-06-19 UVXY XFH59UY2XXT2|UVXY 2T 0.00588235 0.125765
59 2020-06-19 UVXY XFH59ULCKB5Y|UVXY 2T 0.00925 0.133625
58 2020-06-19 UVXY XFH59UWFELBA|UVXY 2T 0.00473333 0.142533
56 2020-06-19 UVXY XFH59UL6LZ46|UVXY 2T 0.00507143 0.152714
55 2020-06-19 UVXY XFH59UURV8TI|UVXY 2T 0.00584615 0.164462
53 2020-06-19 UVXY XFH59UL0NN2E|UVXY 2T 0.00533333 0.178167
17 2020-06-19 I XFH59UQH2JJA|I 2T 0.0025641 0.181795
尝试在 for loop
外写 plt.show()
以显示所有行