我试过在网站上搜索解决方案,但还没有找到一个为我工作的。 我试图绘制一个非常大的热图 - x轴有21个容器,y轴有18个。我从CSV读取数据,大部分情况下,这些单元格都是空的 - 除了少数。我也试图标签的轴。matplotlib - 大型热图
当我绘制热图,它不显示整个事情。我不确定它是否是图形格式或热图的问题。如果我保留任何格式,情节将起作用 - 但它不会显示所有行/列。当我尝试更改轴限制或设置图形的大小时,它实际上会破坏绘图并且数值无法准确显示。
如何使它显示所有列和行,即使值单元格为空?
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
x_labels = ['A','B','C','D','E','F'
'G','H','I','J','K','L',
'M','N','O','P','Q','R',
'S','T','U']
y_labels =['A','B','C','D','E','F','G','H','I','J',
'K','L','M','N','O','P','Q','R']
#reading in a CSV, data in the file is mostly empty - only 3 of the cells have values in them. I included a link to what the .csv looks like
metrics = pd.read_csv("filename.csv", index_col=0)
fig, ir = plt.subplots()
heatmap = ir.pcolor(metrics, cmap=plt.cm.Spectral)
#trying to set the axis labels. Should this reference the column and row labels in the csv instead of the variable I created?
ir.set_xticklabels(x_labels, minor=False)
ir.set_yticklabels(y_labels, minor=False)
ir.invert_yaxis()
plt.show()
这里是什么样的csv
文件看起来像截图:
这是我得到的
情节这是数据帧的打印截图
你检查,如果所有的数据被转移到变量'metrics'正确?也许你通过删除'.csv'导入并生成虚拟数据来测试python itselve来减少你的例子。 – BerndGit
[这里](http://stackoverflow.com/questions/2709050/draw-csv-file-data-as-a-heatmap-using-numpy-and-matplotlib)是一个可能有用的例子。首先检查数据是否正确加载,然后确保绘图正确。 –
我做了一个简单的打印(度量),输出显示整个csv被正确读入。 –