2016-11-10 18 views
1

我在網格上(XY)使用下面的代碼數據繪圖Z(二進制)來改變markersize:無法同時使用plt.scatter用三個變量

plt.scatter(X,Y,Z,顏色=」 c',marker ='o')

結果正常。但我希望在相同的代碼中增加標記大小。請協助。

回答

0

可以使用s關鍵字參數更改標記尺寸,像這樣:

plt.scatter(x,y,z, color='c', marker= 'o', s=100) 

完整例如:

import numpy as np, matplotlib.pyplot as plt 
from mpl_toolkits.mplot3d import Axes3D 

#make some data similar to your description 
a = np.linspace(0.,5.,10) 
x,y = np.meshgrid(a,a) 
z = np.random.randint(low=0,high=2,size=100).reshape(10,10) 

#plot in 3D with s=100 
fig = plt.figure() 
ax = fig.add_subplot(111,projection='3d') 
ax.scatter(x,y,z,marker='o',s=100) 

#or plot in 2D and colour the points by z (sometimes easier to look at than 3d) 
fig1,ax1 = plt.subplots() 
ax1.scatter(x,y,c=z,marker='o',s=100,cmap="Blues") 

這將產生以下情節:

enter image description here

enter image description here