I use iPython notebook a lot together with matplotlib and whilst there are lots of cases when I am happy it automatically displays the images when I call imshow() there are moments when I would like to prevent that behavior.
Specifically I am looping over a very large array and generate a figure in matplotlib for each element which should be saved to disk. As part of that figure creation I have to call imshow() to draw an existing image (in my case the screenshot of a map) to the axis to later on draw additional material on top of that. Whenever I call imshow as part of the process the final figure is displayed inline in iPython notebook, how can I prevent that?
My code looks something like this:
import matplotlib as plt
fig = plt.pyplot.figure(figsize=(20,20))
im2 = plt.pyplot.imread('/some/dir/fancy-map.png')
# Magic to calculate points, x_min etc.
fig.clf()
ax = fig.gca(xlim=(x_min, x_max), ylim=(y_min, y_max))
ax.imshow(im2, extent=(4, 4.5746, 42.5448, 43.3791), aspect=1.5)
raster = ax.imshow(points, vmin = 0, vmax=maxval, extent=(x_min, x_max, y_min, y_max), aspect=1.5, origin='lower')
fig.colorbar(raster)
ax.set_title('coordinates plot')
fig.savefig("fancy-annotated-map.png", bbox_inches=0)