-1

I'm attempting to animate a heatmap in matplotlib, which for the first time in a few hours is functioning, however the graph is very very small, as seen below.Very small graph

The code I am using is as follows:

import numpy as np
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import xarray

Writer = animation.writers['ffmpeg']
writer = Writer(fps=15, metadata=dict(artist='Me'), bitrate=1800)

x = a[var]['lat'].values # Formatted as follows: [-32,-33,-34,-35,-36...]
y = a[var]['lon'].values # Formatted as follows: [150.2, 151.2, 153.2...]
z = np.array(a[var].values) # [[[24,22,18,23,24,24,25]
                            #   [18,25,23,22,21,19,26]
                            #   ...
                            #   [12,28,19,22,25,26,19]]
                            #  ...
                            #  [[8,4,16,12,22,24,23,8]
                            #   ...
                            #   [12,28,14,7,8,13,6,12]]]
fig = plt.figure()
ax = fig.add_subplot(len(x),len(y),1)
def plot(i):
    data = z[i]
    heatmap = ax.pcolor(x, y, data)
ani = animation.FuncAnimation(fig, plot, interval=1, frames=20)
ani.save('im.mp4', writer=writer)

I should also mention attempting to call plt.subplots(x,y) causes the console to freeze and after 5 minutes it still hadn't progressed.

If anyone has an ideas or suggestions they would be much appreciated.

Silver
  • 67
  • 9
  • Apparently you are creating a subplot grid of `len(x)*len(y)` entries and only populate the first one of them. What would be the purpose of this? Do you want to have several subplots appear one-by-one on screen? I would suggest you change the line to `ax = fig.add_subplot(111)` and report back what's missing. – ImportanceOfBeingErnest Jan 21 '19 at 23:16

1 Answers1

0

The line ax = fig.add_subplot(len(x),len(y),1) should be ax = fig.add_subplot(111). The code works after this change.

Silver
  • 67
  • 9