In [11]:
%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 [12]:
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 [13]:
# YOUR CODE HERE
data = np.loadtxt("yearssn.dat")
year = data[:,0]
ssc = data[:,1]
In [14]:
print(year)
print(ssc)
In [5]:
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 [6]:
# YOUR CODE HERE
#http://matplotlib.org/examples/pylab_examples/spine_placement_demo.html
fig = plt.figure(figsize=(12,1))
ax = fig.add_subplot(1, 1, 1)
ax.set_title("Sunspot Activity")
ax.plot(year, ssc)
plt.xlabel("Year")
plt.ylabel("Sunspot Count")
ax.grid(True)
ax.spines["right"].set_visible(False)
ax.spines["top"].set_visible(False)
In [7]:
assert True # leave for grading
Describe the choices you have made in building this visualization and how they make it effective.
The default color and line style worked well for the data, so I didn't change those. I adjusted the aspect ratio of the graph to get a reasonable slope, as per the instructions. I also added labels, and removed the upper and right spines.
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 [28]:
print(year[0:100])
print(len(year[0:100]))
print(len(ssc[0:100]))
In [33]:
# YOUR CODE HERE
fig, ax = plt.subplots(4, 1, figsize=(12,12))
plt.sca(ax[0])
plt.plot(year[0:100], ssc[0:100])
plt.ylabel("Sunspots")
plt.xlabel("Year")
plt.sca(ax[1])
plt.plot(year[100:200], ssc[100:200])
plt.ylabel("Sunspots")
plt.xlabel("Year")
plt.sca(ax[2])
plt.plot(year[200:300], ssc[200:300])
plt.ylabel("Sunspots")
plt.xlabel("Year")
plt.sca(ax[3])
plt.plot(year[300:-1], ssc[300:-1])
plt.ylabel("Sunspots")
plt.xlabel("Year")
plt.xlim([2000, 2100])
Out[33]:
In [ ]:
assert True # leave for grading
In [ ]: