热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在heatmap中使反向对角线为白色-Makereversediagonalswhiteinheatmap

Imtryingtodosomethingasseenontheimageisgivenbelow,我试着做一些如下图所示的事情,Justsettingrever

I'm trying to do something as seen on the image is given below, 或者,您可以屏蔽您的数据,并设置一个屏蔽颜色:

#Create test data:
data = np.random.random_sample((25, 25))
#Create a diagonal mask:
mask = np.diag(np.ones(25))
#Apply mask to data:
masked_data = ma.masked_array(data, mask)
#Set mask color to white:
cm.jet.set_bad(color='white', alpha=None)
#for this to work we use pcolormesh instead of pcolor:
pcolormesh(masked_data, cmap=cm.jet)
colorbar()
show()

This produces essentially the same result, but may suit your needs better as you can set any cell to white, and also the white doesn't show up on the colorbar (see very bottom of above colorbar):

这产生了本质上相同的结果,但可能更适合您的需要,因为您可以将任何单元格设置为白色,而且白色也不会出现在colorbar上(参见上面的colorbar最下面):

enter image description here

#2


1  

The colormap is defined by the cmap argument in ax.imshow(). You have used the jet colormap so you have cmap=cm.jet, which is just one of many built-in color maps in matplotlib. You may choose one or define your own that suits your taste.

colormap是由ax.imshow()中的cmap参数定义的。您已经使用了jet colormap,所以您有cmap=cm。jet是matplotlib中许多内置的彩色地图之一。你可以选择一种,也可以定义适合自己口味的。


推荐阅读
author-avatar
mobiledu2502891023
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有