matplotlib绘制数据点但它们之间没有直线?

2024-10-02 16:31:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我想绘制一个在同一个轴上有多个数据集的折线图,这样标记会显示出来,但不会显示直线。我真的看不出我做错了什么。有人能再看一眼吗?在

数据打印如下:

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

代码段如下:

^{pr2}$

this is what is been plotted right now


Tags: 数据标记代码段绘制at直线aashape
1条回答
网友
1楼 · 发布于 2024-10-02 16:31:21

您的问题是您多次调用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()

这可能不是你想要的。我不清楚你想用不同的颜色和标记做什么,所以你可能要修改它。不过,我认为这至少能让你朝着正确的方向前进。在

相关问题 更多 >