In [14]:
%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 [15]:
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 [16]:
data=np.loadtxt('yearssn.dat')
In [17]:
year = data[:,0]
ssc = data[:,1]
In [18]:
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 [69]:
f = plt.figure(figsize=(10,5))
plt.plot(year,ssc)
plt.xlabel('Year')
plt.ylabel('Sunspot Count')
plt.xlim(1700, 2015)
plt.ylim(0, 200)
plt.tick_params(axis='y', direction='out', length=5)
plt.box(False)
In [33]:
assert True # leave for grading
Describe the choices you have made in building this visualization and how they make it effective.
I made my plot longer in the horizontal direction in order to make the years more discernable. I labeled the plot so that my data is understandable. I changed the limits of my axes so that the data fills the chart. I also changed the directions of the y ticks to the outside so they don't overlap onto my line.
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 [73]:
x = plt.figure(figsize=(15,15))
plt.subplot(4,1,1)
plt.plot(year[0:99], ssc[0:99])
plt.ylabel("Sunspot Count")
plt.box(False)
plt.subplot(4,1,2)
plt.plot(year[100:199], ssc[100:199])
plt.box(False)
plt.subplot(4,1,3)
plt.plot(year[200:299], ssc[200:299])
plt.box(False)
plt.subplot(4,1,4)
plt.plot(year[300:], ssc[300:])
plt.xlabel("Year")
plt.box(False)
plt.tight_layout()
In [ ]:
assert True # leave for grading