In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
Download the .txt data for the "Yearly mean total sunspot number [1700 - now]" from the SILSO website. Upload the file to the same directory as this notebook.
In [2]:
import os
assert os.path.isfile('yearssn.dat')
Use np.loadtxt to read the data into a NumPy array called data. Then create two new 1d NumPy arrays named years and ssc that have the sequence of year and sunspot counts.
In [3]:
# YOUR CODE HERE
data = np.loadtxt('yearssn.dat')
year = data[:,0]
ssc = data[:,1]
In [4]:
assert len(year)==315
assert year.dtype==np.dtype(float)
assert len(ssc)==315
assert ssc.dtype==np.dtype(float)
Make a line plot showing the sunspot count as a function of year.
In [5]:
# YOUR CODE HERE
plt.plot(year, ssc)
plt.xlabel('Year')
plt.ylabel('Sun Spots')
plt.title('Sun Spots per Year')
plt.xlim(1700, 2015)
plt.ylim(0, 200)
plt.box(False)
In [6]:
assert True # leave for grading
Describe the choices you have made in building this visualization and how they make it effective.
YOUR ANSWER HERE
Now make 4 subplots, one for each century in the data set. This approach works well for this dataset as it allows you to maintain mild slopes while limiting the overall width of the visualization. Perform similar customizations as above:
In [7]:
# YOUR CODE HERE
In [8]:
year_1 = year[0:100]
In [9]:
ssc_1 = ssc[0:100]
In [10]:
year_2 = year[100:200]
In [11]:
ssc_2 = ssc[100:200]
In [12]:
year_3 = year[200:300]
In [13]:
ssc_3 = ssc[200:300]
In [14]:
year_4 = year[300:315]
In [15]:
ssc_4 = ssc[300:315]
In [16]:
plt.subplot(2,2,1)
plt.plot(year_1, ssc_1)
plt.ylabel('Sun Spots')
plt.box(False)
plt.subplot(2,2,2)
plt.plot(year_2, ssc_2)
plt.box(False)
plt.subplot(2,2,3)
plt.plot(year_3, ssc_3)
plt.xlabel('Year')
plt.ylabel('Sun Spots')
plt.box(False)
plt.subplot(2,2,4)
plt.plot(year_4, ssc_4)
plt.xlabel('Year')
plt.box(False)
In [17]:
assert True # leave for grading