简体   繁体   English

使用 matplotlib.pyplot 在图中绘制许多点

[英]Plotting many points on the figure with matplotlib.pyplot

I would like to plot many points on a figure.我想在一个图上绘制很多点。 The method I use is:我使用的方法是:

main_ax.plot(10, 20, '.w')

This code can help me polt a point at (10, 20)这段代码可以帮助我在 (10, 20)

But I need to plot many points:但我需要绘制很多点:

data = [(13, 45), (13, 46), (13, 47), (13, 48), (13, 49), (13, 50), (13, 51), (13, 52), (13, 53), (13, 54), (14, 40), (14, 41), (14, 42), (14, 43), (14, 44), (14, 55), (14, 56), (14, 57), (14, 58), (14, 59), (15, 37), (15, 38), (15, 39), (15, 60), (15, 61), (15, 62), (16, 35)]

The only way that I know to plot these points is:我知道绘制这些点的唯一方法是:

main_ax.plot(13, 45, '.w')
main_ax.plot(13, 46, '.w')
main_ax.plot(13, 47, '.w')
main_ax.plot(13, 48, '.w')........

Is there any other faster method that I can plot many points?有没有其他更快的方法可以绘制很多点?

Thanks!!!谢谢!!!

You can split your data into two lists of x and y coordinates and do a scatter plot:您可以将数据拆分为两个xy坐标列表并绘制散点图:

x, y = zip(*data)
plt.scatter(x, y)

在此处输入图片说明

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

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