我无法让pyplot颜色条在散点图中配合,我专门设置了facecolors = None,只想显示散乱圆圈的边缘。有人可以指点我正确的方向吗?感谢。
这很好用:
# Solid circles - colorbar shows
plt.scatter(x, y, c=z, s=15, lw=0.3, cmap='viridis')
plt.colorbar()
plt.show()
......但这并不是:
c = plt.cm.viridis(z)
plt.scatter(x, y, facecolors = 'none', edgecolors = c, s = 15, lw = 0.3)
plt.colorbar()
plt.show()
Traceback (most recent call last): File "/API/ML_GenerateFeatures.py", line 221, in
<module> va.scatter_color(df.OIR, df.fwd_delta_mid, df.spread)
File "/API/ML_GenerateFeatures.py", line 184, in scatter_color plt.colorbar()
File "C:\Python27\Lib\site-packages\matplotlib\pyplot.py", line 2180, in colorbar ret = gcf().colorbar(mappable, cax = cax, ax=ax, **kw)
File "C:\Python27\Lib\site-packages\matplotlib\figure.py", line 1844, in colorbar cb = cbar.colorbar_factory(cax, mappable, **kw)
File "C:\Python27\Lib\site-packages\matplotlib\colorbar.py", line 1365, in colorbar_factory cb = Colorbar(cax, mappable, **kwargs)
File "C:\Python27\Lib\site-packages\matplotlib\colorbar.py", line 918, in __init__ mappable.autoscale_None()
File "C:\Python27\Lib\site-packages\matplotlib\cm.py", line 348, in autoscale_None
raise TypeError('You must first set_array for mappable')
TypeError: You must first set_array for mappable