-2

Below code plots a heatmap from a matrix, but it returns an image. I want a figure to be returned. Please let me know how would i achieve it.

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()

1 Answers1

0

Well, to get a figure object, you should initialize it first with fig = figure(), but then you should also create your other objects as childs of fig, otherwise the returned figure will have nothing to do with your axes. That is why you should understand what is happening in the background.

jake77
  • 1,892
  • 2
  • 15
  • 22