【问题标题】:How to plot a heatmap from a matrix using matplotlib which would return a figure如何使用 matplotlib 从矩阵绘制热图,这将返回一个数字
【发布时间】:2016-01-12 02:25:09
【问题描述】:

以下代码从矩阵绘制热图,但它返回图像。我想返回一个数字。请让我知道我将如何实现它。

from numpy.matlib import rand
from pylab import *
import matplotlib.pyplot as plt

A = []

i = input('Enter number of rows: ')
j = input('Enter number of columns: ')
for x in range(i):
    row = []
    for y in range(j):
        k = input('enter the value: ')
        row.append(k)
    A.append(row)
print A

figure(2)
plt.imshow(A, aspect=(0.1), interpolation='nearest', origin='lower', extent=(0, 10, 0, 100))
plt.grid(True)
plt.xlabel('abc', fontsize=15)
plt.ylabel('xyz', fontsize=15)
plt.show()

【问题讨论】:

  • this 问题的公认答案可能就是您所需要的。
  • 我无法理解

标签: python python-2.7 matplotlib


【解决方案1】:

好吧,要获得一个图形对象,您应该首先使用fig = figure() 对其进行初始化,然后您还应该将其他对象创建为fig 的子对象,否则返回的图形将与您的轴无关。这就是为什么您应该了解后台发生的事情。

【讨论】:

    猜你喜欢
    • 2013-09-18
    • 1970-01-01
    • 2021-03-12
    • 2019-08-09
    • 2013-12-12
    • 1970-01-01
    • 1970-01-01
    • 2016-12-08
    • 2017-07-01
    相关资源
    最近更新 更多