栏目分类:
子分类:
返回
文库吧用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
文库吧 > IT > 面试经验 > 面试问答

海本热图图中的离散图例

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

海本热图图中的离散图例

好吧,要做到这一点肯定不止一种方法。在这种情况下,
由于只需要三种颜色,我会选择自己的颜色创建一个

LinearSegmentedColormap
而不是使用“cubehelixu palete”生成它们。
如果有足够的颜色来保证使用“cubehelixu调色板”,我会的
使用
cbar_kws
参数。无论哪种方式,都可以使用手动指定记号
设置记号和标签。下面的代码示例演示如何手动创建
LinearSegmentedColormap`,并包含有关如何指定边界的注释
如果改用“cubehelixu palete”。

import matplotlib.pyplot as pltimport pandasimport seaborn.apionly as snsfrom matplotlib.colors import LinearSegmentedColormapsns.set(font_scale=0.8)dataframe = pandas.read_csv('LUH2_trans_matrix.csv').set_index(['Unnamed: 0'])# For only three colors, it's easier to choose them yourself.# If you still really want to generate a colormap with cubehelix_palette instead,# add a cbar_kws={"boundaries": linspace(-1, 1, 4)} to the heatmap invocation# to have it generate a discrete colorbar instead of a continous one.myColors = ((0.8, 0.0, 0.0, 1.0), (0.0, 0.8, 0.0, 1.0), (0.0, 0.0, 0.8, 1.0))cmap = LinearSegmentedColormap.from_list('Custom', myColors, len(myColors))ax = sns.heatmap(dataframe, cmap=cmap, linewidths=.5, linecolor='lightgray')# Manually specify colorbar labelling after it's been generatedcolorbar = ax.collections[0].colorbarcolorbar.set_ticks([-0.667, 0, 0.667])colorbar.set_ticklabels(['B', 'A', 'C'])# X - Y axis labelsax.set_ylabel('FROM')ax.set_xlabel('TO')# only y-axis labels need their rotation set, x-axis labels already have a rotation of 0_, labels = plt.yticks()plt.setp(labels, rotation=0)plt.show()


转载请注明:文章转载自 www.wk8.com.cn
本文地址:https://www.wk8.com.cn/it/640043.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 wk8.com.cn

ICP备案号:晋ICP备2021003244-6号