我想在同一轴上绘制包含多个数据集的折线图,因此标记显示但不显示。我真的无法看到我做错了什么。有人可以再戴上另一双眼睛吗?
这是数据打印:
looking at 2015-08-05 83.0 AA attribs sector= Materials shape= o kolor= b x = 2015-08-05 y = 83.0
looking at 2015-08-06 50.0 AA attribs sector= Materials shape= o kolor= b x = 2015-08-06 y = 50.0
looking at 2015-08-07 42.0 AA attribs sector= Materials shape= o kolor= b x = 2015-08-07 y = 42.0
looking at 2015-08-10 75.0 AA attribs sector= Materials shape= o kolor= b x = 2015-08-10 y = 75.0
以下是代码段:
for count, symb in enumerate(my_symbols):
sector = sector_format[str(sym_sect[symb])][0]
shape = sector_format[str(sym_sect[symb])][1]
kolor = sector_format[str(sym_sect[symb])][2]
x = my_dates[count]
y = rank_2010[count]
print("looking at",x,y,symb,"attribs",
"sector=",sector,
"shape=",shape,
"kolor=",kolor,
"x =",x,
"y = ",y)
if symb == 'AA' or symb == "AAPL":
plt.plot(x,y,lw=5,color=kolor,linestyle='solid',marker=shape)
plt.title('hv 20 to 10 ranks')
plt.xlabel('dates')
plt.ylabel('symbol ranks')
plt.show()
答案 0 :(得分:1)
您的问题是您多次致电plot
,希望它将您提供的数据收集到一组中。这不是plot
的工作方式。您需要形成一个数据集(图中的一个“线”)并将其传递给plot
。有点像:
x_list = []
y_list = []
for count, symb in enumerate(my_symbols):
sector = sector_format[str(sym_sect[symb])][0]
shape = sector_format[str(sym_sect[symb])][1]
kolor = sector_format[str(sym_sect[symb])][2]
x = my_dates[count]
y = rank_2010[count]
print("looking at",x,y,symb,"attribs",
"sector=",sector,
"shape=",shape,
"kolor=",kolor,
"x =",x,
"y = ",y)
if symb == 'AA' or symb == "AAPL":
x_list.append(x)
y_list.append(y)
plt.plot(x_list,y_list,lw=5,color=kolor,linestyle='solid',marker=shape)
plt.title('hv 20 to 10 ranks')
plt.xlabel('dates')
plt.ylabel('symbol ranks')
plt.show()
这可能不是您想要的。我不清楚你要用不同的颜色和标记做什么,所以你可能需要修改它。但是,我认为至少应该让你朝着正确的方向前进。