Plotting a difference image

How to compute and plot a difference image. The example uses to compute a difference image and then plot it. This basic method works for base difference or running difference. Just change whether you’re subtracting the previous image or the first image in a sequence.

import matplotlib.colors as colors
import matplotlib.pyplot as plt

import astropy.units as u


First load a couple of images taken from the sample dataset. These are two cutouts taken during a flare.

Now we’ll do a standard plot of the second image just to see it.

ax = plt.subplot(projection=maps[1])
maps[1].plot(clip_interval=(0.5, 99.9)*u.percent)
AIA $193 \; \mathrm{\mathring{A}}$ 2011-06-07 06:52:19


<matplotlib.image.AxesImage object at 0x7f22750389d0>

And now we can do take the actual difference.

diff = maps[1].data - maps[0].data

But we have to decide what to do with the metadata. For example, what time does this difference image correspond to? The time of the first or second image? The mean time? You’ll have to decide what makes most sense for your application. Here we’ll just use the metadata from the second image. Then we can store the difference and header back in a Map.

meta = maps[1].meta
diff_map =, meta)

Finally, we’ll plot it. We’ll apply a colormap and re-normalize the intensity so that it shows up well.

              norm=colors.Normalize(vmin=-200, vmax=200))
plt.colorbar(extend='both', label=maps[1].unit.to_string())
AIA $193 \; \mathrm{\mathring{A}}$ 2011-06-07 06:52:19

Total running time of the script: ( 0 minutes 0.964 seconds)

Gallery generated by Sphinx-Gallery