Removing the grid lines from MapSequence plots

Hi all. I have been having trouble trying to remove the grid lines from animations created by the plot method of sunpy.map.MapSequence. Assuming we start with something like

import matplotlib.pyplot as plt
from astropy.visualization import ImageNormalize, SqrtStretch
import sunpy.data.sample
import sunpy.map

seq = sunpy.map.Map([
    sunpy.data.sample.AIA_193_CUTOUT01_IMAGE,
    sunpy.data.sample.AIA_193_CUTOUT02_IMAGE,
    sunpy.data.sample.AIA_193_CUTOUT03_IMAGE,
    sunpy.data.sample.AIA_193_CUTOUT04_IMAGE,
    sunpy.data.sample.AIA_193_CUTOUT05_IMAGE,
], sequence=True)

fig = plt.figure()
ax = fig.add_subplot(projection=seq.maps[0])
ani = seq.plot(axes=ax, norm=ImageNormalize(vmin=0, vmax=5e3, stretch=SqrtStretch()))

plt.show()

how would you go about removing the grid lines? It does not appear to be as simple as adding plt.grid(False) or ax.coords.grid(False) which usually works for static plots. Passing a plot_function as a kwarg to the plot method does not seem to work either.

Any help with this would be greatly appreciated.

Hi @Trestan,

Can you see if adding the following plot_function works for you?

def plot_function(fig, ax, smap):
    ax.coords.grid(False)
    return []

ani = seq.plot(axes=ax, norm=ImageNormalize(vmin=0, vmax=5e3, stretch=SqrtStretch()), plot_function=plot_function)
1 Like

Thank you @nabobalis ! This works. With this solution the first frame still has grid lines, but I was able to remove them by calling plot_function before plt.show().

I had naively tried

def plot_function(fig, ax, smap):
    return [ax.coords.grid(False)]

which did not work.

Yeah the documentation for that function is pretty poor.