python用plt画图时,cmp设置方法
在python,有时候是需要画图的,比如把一个矩阵用图像的形式显示,之前用的好好的,每次用plt.imshow(),都是彩色图,不知为啥,突然全是黑白图了,于是需要设置cmap的值,如下:
plt.imshow(confusion_matrix_percent,cmap='gray') plt.colorbar() plt.show()
在上面的代码中,设置cmap=‘gray',表示绘制灰度图,若需要绘制彩色图,可设置其它值,个人比较喜欢用PRGn或者PRGn_r
cmap的候选值有
'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','Vega10','Vega10_r','Vega20','Vega20_r','Vega20b','Vega20b_r','Vega20c','Vega20c_r','Wistia','Wistia_r','YlGn','YlGnBu','YlGnBu_r','YlGn_r','YlOrBr','YlOrBr_r','YlOrRd','YlOrRd_r','afmhot','afmhot_r','autumn','autumn_r','binary','binary_r','bone','bone_r','brg','brg_r','bwr','bwr_r','cool','cool_r','coolwarm','coolwarm_r','copper','copper_r','cubehelix','cubehelix_r','flag','flag_r','gist_earth','gist_earth_r','gist_gray','gist_gray_r','gist_heat','gist_heat_r','gist_ncar','gist_ncar_r','gist_rainbow','gist_rainbow_r','gist_stern','gist_stern_r','gist_yarg','gist_yarg_r','gnuplot','gnuplot2','gnuplot2_r','gnuplot_r','gray','gray_r','hot','hot_r','hsv','hsv_r','inferno','inferno_r','jet','jet_r','magma','magma_r','nipy_spectral','nipy_spectral_r','ocean','ocean_r','pink','pink_r','plasma','plasma_r','prism','prism_r','rainbow','rainbow_r','seismic','seismic_r','spectral','spectral_r','spring','spring_r','summer','summer_r','tab10','tab10_r','tab20','tab20_r','tab20b','tab20b_r','tab20c','tab20c_r','terrain','terrain_r','viridis','viridis_r','winter','winter_r'
以上这篇python用plt画图时,cmp设置方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。