Plot Larger Points On Bottom And Smaller On Top
I'm looking for a way to produce a scatter plot in python where smaller plots will be drawn above larger ones to improve the figure's 'readability' (is there a similar word for an
Solution 1:
Apply sort
before plotting
order = np.argsort(-z1) # for descx = np.take(x, order)
y = np.take(y, order)
z1 = np.take(z1, order)
z2 = np.take(z2, order)
The figure using alpha
is more readable.
import numpy as np
import matplotlib.pyplot as plt
def random_data(N):
# Generate some random data.
return np.random.uniform(70., 250., N)
# Data lists.
N = 1000
x = random_data(N)
y = random_data(N)
z1 = random_data(N)
z2 = random_data(N)
order = np.argsort(-z1)
x = np.take(x, order)
y = np.take(y, order)
z1 = np.take(z1, order)
z2 = np.take(z2, order)
cm = plt.cm.get_cmap('RdYlBu')
plt.scatter(x, y, s=z1, c=z2, cmap=cm, alpha=0.7) # alpha can be 0 ~ 1
plt.colorbar()
plt.show()
The output is
Post a Comment for "Plot Larger Points On Bottom And Smaller On Top"