简体   繁体   English

matplotlib 的不同数据点的不同颜色

[英]Different colors for different datapoints for matplotlib

I have my x and y coordinates saved in variable x and y respectively.我将 x 和 y 坐标分别保存在变量 x 和 y 中。 Below is the plot that I get when I make a scatter plot using x,y coordinates.下面是我使用 x,y 坐标绘制散点图时得到的图。 The code used to make the plot is:用于制作绘图的代码是:

import matplotlib.pyplot as plt
for i in range(len(x)):
    plt.scatter(x[i], y[i])

观察到的情节

My question is that even though no color parameter was provided, plt.scatter automatically assigned different colors to the data points though the official documentation suggests that the default value is "b" as for "blue".我的问题是,即使没有提供颜色参数,plt.scatter 会自动为数据点分配不同的颜色,尽管官方文档建议默认值为“b”,“蓝色”。

The default seems to be None rather than b (although the detailed description of the parameters tells differently).默认似乎是None而不是b (尽管参数的详细描述有所不同)。

From the doc : matplotlib.pyplot.scatter(x, y, s=None, c=None,...来自文档matplotlib.pyplot.scatter(x, y, s=None, c=None,...

So in your case you can fix it with:因此,在您的情况下,您可以使用以下方法修复它:

for i in range(len(x)):
    plt.scatter(x[i], y[i], c="b")

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

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