簡體   English   中英

matplotlib 數據點繪制但它們之間沒有線?

[英]matplotlib data points plotted but no line between them?

我想在同一軸上繪制具有多個數據集的折線圖,因此會顯示標記但不顯示線條。 我真的看不出我做錯了什么。 請問有人可以再看一下嗎?

這是打印數據:

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()

這是現在繪制的

您的問題是您多次調用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()

這可能不是您想要的。 我不清楚你想用不同的顏色和標記做什么,所以你可能需要修改它。 但是,我認為它至少應該讓您朝着正確的方向前進。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM