2016-07-13 2 views
0

В приведенном ниже примере игрушки я хотел бы сделать условные цвета на моем участке разброса таким образом, что для всех значений, например, 3 < xy < 7, непрозрачность точек разброса равна альфа = 1, а для остальных они имеют альфа < 1.Условные цвета в диаграмме рассеяния

xy = np.random.rand(10,10)*100//10 
print xy 

# Determine the shape of the the array 

x_size = np.shape(xy)[0] 
y_size = np.shape(xy)[1] 

# Scatter plot the array 

fig = plt.figure() 
ax = fig.add_subplot(111) 
xi, yi = np.meshgrid(range(x_size), range(y_size)) 
ax.scatter(xi, yi, s=100, c=xy, cmap='RdPu') 
plt.show() 

enter image description here enter image description here

ответ

1

Используйте замаскированной массив из NumPy и сюжет разброса дважды:

import matplotlib.pyplot as plt 
import numpy as np 

xy = np.random.rand(10,10)*100//10 
x_size = np.shape(xy)[0] 
y_size = np.shape(xy)[1] 

# get interesting in data 
xy2 = np.ma.masked_where((xy > 3) & (xy < 7), xy) 
print xy2 

# Scatter plot the array 
fig = plt.figure() 
ax = fig.add_subplot(111) 
xi, yi = np.meshgrid(xrange(x_size), xrange(y_size)) 
ax.scatter(xi, yi, s=100, c=xy, cmap='RdPu', alpha = .5, edgecolors='none') # plot all data 
ax.scatter(xi, yi, s=100, c=xy2, cmap='bone',alpha = 1., edgecolors='none') # plot masked data 
plt.show() 

enter image description here

Смежные вопросы