简体   繁体   English

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

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

I want to plot a line chart with multiple data sets on the same axes, so the markers show up but not the line.我想在同一轴上绘制具有多个数据集的折线图,因此会显示标记但不显示线条。 I really can't see what I am doing wrong.我真的看不出我做错了什么。 Can someone put another set of eyes on this, please?请问有人可以再看一下吗?

Here is the data print:这是打印数据:

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

Here is the code segment:这是代码段:

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

这是现在绘制的

Your problem is that you are calling plot multiple times wanting it to collect the data you give it into one set.您的问题是您多次调用plot ,希望它将您提供的数据收集到一组中。 That's not how plot works.这不是plot运作方式。 You need to form a data set (one "line" in your plot) and pass that to plot .您需要形成一个数据集(图中的一条“线”)并将其传递给plot Something along the lines of:类似的东西:

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

This may not be exactly what you want.这可能不是您想要的。 I'm unclear on what you're trying to do with different colors and marks, so you may have to modify it.我不清楚你想用不同的颜色和标记做什么,所以你可能需要修改它。 However, I think it should get you in the right direction at least.但是,我认为它至少应该让您朝着正确的方向前进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM