简体   繁体   English

Python 2D热图中的行数增加

[英]Increasing Number of Rows in Python 2D Heatmap

I am plotting python heatmap. 我正在绘制python热图。 Following is the code I am using. 以下是我正在使用的代码。

df = pd.read_csv('Book1.csv', index_col=0)
print (df)
# plotting
fig,ax = plt.subplots()
ax.matshow(df.mask(df.isin(df.att1)!=1), cmap=cm.Reds) 
ax.matshow(df.mask(df.isin(df.att2)!=1), cmap=cm.Greens)
ax.matshow(df.mask(df.isin(df.att3)!=1), cmap=cm.Blues)
#ax.matshow(df.mask(df.isin(df.att4)!=1), cmap=cm.Reds) 
#ax.matshow(df.mask(df.isin(df.att5)!=1), cmap=cm.Greens)
#ax.matshow(df.mask(df.isin(df.att6)!=1), cmap=cm.Blues)
plt.xticks(range(3), df.columns)
plt.yticks(range(864), df.index)
plt.show()  

df consists of data of the form: df由以下形式的数据组成:

    att1  att2 att3

fun1  1     2     1     
fun2  1     0     0     

  .......

  ....

This code is working fine if I used few rows like 10-12. 如果我使用了10-12之类的几行代码,此代码就可以正常工作。 Giving following output: 提供以下输出: 在此处输入图片说明

However if I increase number of rows equal to 800 the graph is looking like garbage. 但是,如果我增加等于800的行数,则该图看起来就像垃圾。 Following is the output: 以下是输出: 在此处输入图片说明

Image after removing plt.yticks: 删除plt.yticks后的图片: 在此处输入图片说明

Does anyone have any idea, how can I increase number of rows in this kind of heatmap? 有谁知道,如何在这种热图中增加行数?

You can use aspect option, but for the y-ticks, I'm not sure it's useful to have them all since it will be unreadable, but you can set some : 您可以使用aspect选项,但是对于y-ticks,我不确定将它们全部包含是否有用,因为它不可读,但是您可以设置一些:

fig, ax = plt.subplots(figsize=(6, 10))

ax.matshow(df.mask(df.isin(df.att1)!=True), cmap=cm.Reds,  aspect='auto')
ax.matshow(df.mask(df.isin(df.att2)!=True), cmap=cm.Greens, aspect='auto')
ax.matshow(df.mask(df.isin(df.att3)!=True), cmap=cm.Blues, aspect='auto')

plt.xticks(range(3), df.columns)
plt.yticks(range(0, 800, 100), df.index[::100])

在此处输入图片说明

Hope this helps 希望这可以帮助

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

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