简体   繁体   中英

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

在此输入图像描述

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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