Hi Emily,
We actually have instruments that can measure the magnetic field at
different points on the Sun, so a magnetic map (called a
magnetogram) of the whole Sun can be made. When such magnetograms
are compared to images of the Sun it is pretty clear that the locations
of the sunspots matches locations of higher magnetic field. If
you take these images/measurements every few minutes or hours, you can
even see how the areas of strong magnetic fields move and change and
how that corresponds to changes in the shape and size and position of
the sunspots.
Best,
Christina