2016-07-13 17 views
0

Im folgenden Spielzeugbeispiel möchte ich in meinem Streudiagramm bedingte Farben machen, so dass für alle Werte, z. B. 3 < xy < 7, die Opazität der Streupunkte alpha = 1 und für den Rest haben sie eine alpha < 1.Bedingte Farben im Streudiagramm

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

Antwort

1

Verwenden maskiert Array aus numpy und Plot scatter zweimal:

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

Verwandte Themen