import matplotlib.pyplot as plt
import numpy as np
x = np.random.rand(1,60)
y = np.random.randn(1,60)
# rand均匀分布,randn高斯分布
plt.scatter(x,y)
plt.show()
python设置scatter颜色渐变
cm = plt.cm.get_cmap('Set1')
plt.scatter(x,y,c=x,cmap=cm)
plt.show()
其中get_cmap中取值可为:Possible values are: Accent, Accent_r, Blues, Blues_r, BrBG, BrBG_r, BuGn, BuGn_r, BuPu, BuPu_r, CMRmap, CMRmap_r, Dark2, Dark2_r, GnBu, GnBu_r, Greens, Greens_r, Greys, Greys_r, OrRd, OrRd_r, Oranges, Oranges_r, PRGn, PRGn_r, Paired, Paired_r, Pastel1, Pastel1_r, Pastel2, Pastel2_r, PiYG, PiYG_r, PuBu, PuBuGn, PuBuGn_r, PuBu_r, PuOr, PuOr_r, PuRd, PuRd_r, Purples, Purples_r, RdBu, RdBu_r, RdGy, RdGy_r, RdPu, RdPu_r, RdYlBu, RdYlBu_r, RdYlGn, RdYlGn_r, Reds, Reds_r, Set1, Set1_r, Set2, Set2_r, Set3, Set3_r, Spectral, Spectral_r, Wistia, Wistia_r, YlGn, YlGnBu, YlGnBu_r, YlGn_r, YlOrBr, YlOrBr_r, YlOrRd, YlOrRd_r...其中末尾加r是颜色取反
作者:yefengzhichen
来源:CSDN
原文:https://blog.csdn.net/yefengzhichen/article/details/52757722?utm_source=copy
版权声明:本文为博主原创文章,转载请附上博文链接!
渐变色添加颜色条
cm = plt.cm.get_cmap('Set1')
fig = plt.scatter(x,y,c=x,cmap=cm)
plt.colorbar(fig)
plt.show()
参考文献
- 1 https://blog.csdn.net/yefengzhichen/article/details/52757722
- 2 https://blog.csdn.net/AlienDaniel/article/details/56479546?utm_source=blogxgwz6