简体   繁体   English

关于如何添加颜色的散点图?

[英]Scatter plot on how to add color?

The code could plot but it just has one color.代码可以绘制,但它只有一种颜色。 So it could not figure out the color of 4 areas.所以它无法弄清楚4个区域的颜色。

What should be added for it?应该为它添加什么?

  from matplotlib import pyplot as plt 
  %matplotlib inline

  plt.title("rate in four areas")
  plt.ylabel("rate") #Y axis label
  plt.xlabel("Year")
  plt.scatter(df['Year'], df['rate'])

  plt.tight_layout()
  plt.legend(bbox_to_anchor=(1, 1))
  plt.show()

Is df_three a tuple containing lists, such that df_three['Year'] is a list in itself? df_three 是一个包含列表的元组,这样 df_three['Year'] 本身就是一个列表吗? Or does df_three['Year'] have three lists in each element, and you're plotting them all together at the same time.或者 df_three['Year'] 是否在每个元素中有三个列表,并且您将它们同时绘制在一起。

If the latter is true, try如果后者为真,请尝试

plt.scatter(df_three['Year'][0], df_three['co2'])
plt.scatter(df_three['Year'][1], df_three['co2'])
plt.scatter(df_three['Year'][2], df_three['co2'])
plt.scatter(df_three['Year'][3], df_three['co2'])

Not the most elegant solution but I'm not sure what you're doing because you haven't provided enough information.不是最优雅的解决方案,但我不确定你在做什么,因为你没有提供足够的信息。

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

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