就像这样:
import pandas as pd
from numpy.random import random_integers
from numpy import reshape
import matplotlib.pyplot as plt
from matplotlib.ticker import FixedLocator, FixedFormatter
alph = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
lalph = list(alph.lower())
alph = list(alph)
df = pd.DataFrame(random_integers(0,100,(26,26)),columns=alph,
index=lalph)
# Two lines just to make a plaid image in imshow
differ = reshape([sum(df[col2]-df[col]) for col2 in df for col in df], (26,26))
differ = pd.DataFrame(differ, columns=alph,index=alph)
# pick the labels you want
ticks = [2, 14, 18, 19, 22] # C=2 because A=0 because Python is 0-indexed
ticklabels = [alph[x] for x in ticks]
fig = plt.figure(figsize=(3,5))
ax = fig.add_subplot(111)
ax.imshow(differ)
ax.autoscale(False)
# display only the chosen ticks and ticklabels
ax.xaxis.set_major_locator(FixedLocator(ticks))
ax.xaxis.set_major_formatter(FixedFormatter(ticklabels))
您将拥有一组字符串,这些字符串命名基因,而不是作为字母列表使用的字符串,但imshow轴索引仍然是基础numpy数组的索引。
ax.xticks',
ax.set_xticklabels` 可能已经足够了。 - cphlewis