简体   繁体   English

定性热图情节python

[英]Qualitative heatmap plot python

I have a matrix with sales per year for clients. 我有一个矩阵,每年为客户销售。 Column wise I wish to have years. 我希望有多年的专栏。 Line wise I wish to have companies. 我希望有公司。 Color is indicative for the value (number of sales per year per client). 颜色表示价值(每个客户每年的销售数量)。

It is a heatmap with discrete qualitative (clients name) variable. 它是具有离散定性(客户名称)变量的热图。

How could I display this ? 我怎么能显示这个?

EDIT: 编辑:

to rephrase, this is about creating an heatmap with a label per row (or a left label per cell). 换句话说,这是关于创建一个每行标签(或每个单元格左侧标签)的热图。 heatmap is plotted with pylab and gives 用pylab绘制热图并给出

在此输入图像描述

I wish to replace graduation on the left with label (discrete qualitative). 我希望用标签(离散定性)替换左侧的刻度。

I'm not exactly sure what you are trying to achieve, but this code 我不确定你想要实现什么,但是这段代码

import numpy as np
import matplotlib.pyplot as plt

data = np.random.random((20, 3))

plt.imshow(data, interpolation='none', aspect=3./20)

plt.xticks(range(3), ['a', 'b', 'c'])

plt.jet()
plt.colorbar()

plt.show()

seems to produce what you want: 似乎产生了你想要的东西: 在此输入图像描述

nicking most of the code off of David Zwicker: 将大部分代码从David Zwicker中删除:

import numpy as np
import matplotlib.pyplot as plt

data = np.random.random((20, 3))
# make sure that the normalization range includes the full range we assume later
# by explicitly including `vmin` and `vmax`
plt.imshow(data, interpolation='none', aspect=3./20, vmin=0, vmax=1)

plt.xticks(range(3), ['a', 'b', 'c'])

plt.jet()
cb = plt.colorbar()
cb.set_ticks([0, .5, 1])  # force there to be only 3 ticks
cb.set_ticklabels(['bad', 'ok', 'great!'])  # put text labels on them

plt.show()

Which gives: 这使:

在此输入图像描述

which is what I think you want. 这就是我你想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM