我试着在熊猫身上做顺序颜色图。这是我的结果,我想做彩色地图。在
A G C T -
A - 5823 1997 1248 962
G 9577 - 2683 2492 788
C 2404 2574 - 9569 722
T 1272 1822 5931 - 767
- 795 583 599 559 -
df = pd.DataFrame(index= ["A", "G", "C", "T", "-"], columns=["A", "G", "C", "T", "-"])
import matplotlib.pyplot as plt
import numpy as np
column_labels = list("AGCT-")
row_labels = list("AGCT-")
data = df
fig, ax = plt.subplots()
heatmap = ax.pcolor(data, cmap=plt.cm.Blues)
ax.set_xticks(np.arange(data.shape[0])+0.5, minor=False)
ax.set_yticks(np.arange(data.shape[1])+0.5, minor=False)
ax.invert_yaxis()
ax.xaxis.tick_top()
ax.set_xticklabels(row_labels, minor=False)
ax.set_yticklabels(column_labels, minor=False)
plt.show()
但它总是出错。在
^{pr2}$
问题是数据帧中的“-”字符导致值存储为字符串,而不是整数。在
您可以像这样将数据帧转换为整数(第一部分将“-”替换为0,第二部分将数据类型更改为int):
相关问题 更多 >
编程相关推荐