Making the marker size as small as possible with matplotlib.pyplot
Asked Answered
H

2

6

My program can generate up to 2000000 points within 5 seconds, so I don't have a problem with speed. Right now I am using matplotlib.pyplot.scatter to scatter all my points on my graph. For s=1, it gives me small circles, but not small enough, because it does not show the intricate patterns. When I use s=0.1, it gives me this weird marker shape:

enter image description here

Which makes the marker larger despite me making the size smaller. I have searched all over the internet including stack overflow, but they do not tell how to minimize the size further. Unfortunately, I have to show all the points, and cannot just show a random sample of them.

I have come to the conclusion that matplotlib is made for a small sample of points and not meant for plotting millions of points. However, if it is possible to make the size smaller please let me know.

Anyway, for my points, I have all the x values in order in one array, and all the y values in order in another array. Could someone suggest a graphing package in python I could use to graph all the points in a way that the size would be very small since when I plot the points now it just becomes one big block of color instead of intricate designs forming in the shape as they should be.

Thanks for any help in advance!


EDIT: My code that I am using to scatter the points is:

plt.savefig(rootDir+"b"+str(Nvertices)+"_"+str(xscale)+"_"+str(yscale)+"_"+str(phi)+"_"+str(psi)+"_"+CurrentRun+"_color.png", dpi =600)

EDIT: I got my answer, I added linewidths = 0 and that significantly reduced the size of the points, giving me what I needed.

Hilbert answered 8/2, 2020 at 21:26 Comment(1)
Your question doesn't show any code, so it is hard to guess which parameters you're using. You might try to remove the boundary line (lw=0 if you're using plt.scatter)Shovelnose
D
11

Perhaps you can try making the linewidths as 0 i.e., the line width of the marker edges. Notice the difference in the two plots below

fig, ax = plt.subplots(figsize=(6, 4))
plt.scatter(np.random.rand(100000), np.random.rand(100000), s=0.1)

enter image description here

fig, ax = plt.subplots(figsize=(6, 4))
plt.scatter(np.random.rand(100000), np.random.rand(100000), s=0.1, linewidths=0)

enter image description here

Dodecahedron answered 8/2, 2020 at 21:51 Comment(3)
Thank you this helped so much! This definitely improved my program.Hilbert
If you're using plt.plot, the solution is to use markeredgecolor='none' as mentioned by @Shovelnose in the comments of this question.Childbearing
If you are editing the Line2D object after it is generated then use child.set_markeredgewidth(0)Ylla
H
2

you can set the marker to a single pixel using marker=',' in your call to scatter.

See the markers documentation here

Hematology answered 8/2, 2020 at 23:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.