简体   繁体   中英

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)

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:

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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