The Solar Cycle

This example shows the current and possible next solar cycle.

from __future__ import print_function, division

import datetime
import matplotlib.pyplot as plt

import sunpy.timeseries as ts

For this example we will use the SunPy sample data. This code snippet grabs the most current NOAA solar cycle data as a TimeSeries (see SunPy timeseries).

noaa = ts.TimeSeries(NOAAINDICES_TIMESERIES, source='noaaindices')
noaa_predict = ts.TimeSeries(NOAAPREDICT_TIMESERIES, source='noaapredictindices')

Next, we grab a new copy of the data and shift it forward 12 years to simulate the next solar cycle. We will also truncate the data to ensure that we only plot what is necessary.

noaa2 = ts.TimeSeries(NOAAINDICES_TIMESERIES, source='noaaindices') =, freq=datetime.timedelta(days=365*12))
noaa2 = noaa2.truncate('2021/04/01', '2030/01/01')

Finally, we plot both noaa and noaa2 together, with an arbitrary range for the strength of the next solar cycle.

plt.plot(,['sunspot RI'], label='Sunspot Number')
         color='grey', label='Near-term Prediction')
plt.fill_between(,['sunspot low'],
       ['sunspot high'], alpha=0.3, color='grey')

plt.fill_between(,['sunspot RI smooth']*0.4,
       ['sunspot RI smooth']*1.3, alpha=0.3, color='grey',
                 label='Next Cycle Predict')
plt.text('2011-01-01', 120, 'Cycle 24', fontsize=16)
plt.text('2024-01-01', 120, 'Cycle 25', fontsize=16)
plt.ylabel('Sunspot Number')
plt.legend(loc=2, framealpha=0.5)

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

Gallery generated by Sphinx-Gallery