使用带有三个变量的plt.scatter时无法更改标记大小

时间:2016-11-10 04:45:13

标签: python matplotlib scatter

我正在使用以下代码在网格(x-y)数据上绘制z(二进制):

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

结果很好。但我希望在相同的代码中增加标记大小。请帮助。

1 个答案:

答案 0 :(得分:1)

您可以使用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