Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

pyplot.scatter reduce marker size

Here is an example of a scatter plot with high 2D point density, just for illustration.

How can I reduce the size of the markers to better distinguish the individual points? The size of the plot should remain as it is.

import numpy as np
import matplotlib.pyplot as plt
from sklearn import preprocessing
from matplotlib import cm

np.random.seed(10)

n=3000

x = np.arange(n)
z = np.sin(x/n)
y = np.random.randint(0, 100, size=(n))

colvals = preprocessing.minmax_scale(z)

plt.scatter(x, y, color=cm.rainbow(colvals), marker='.')
plt.xlabel('x')
plt.ylabel('y')

plt.show()

enter image description here

Answer*

Cancel
2
  • Side note: I swapped out rainbow for viridis since the rainbow colormap should be avoided when possible.
    – tdy
    Commented Mar 19, 2022 at 0:02
  • 1
    Thanks for the link to the interesting paper, many researchers still use rainbow or monochrome color maps with increasing brightness.
    – len
    Commented Mar 21, 2022 at 7:48