In [2]:
%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 [3]:
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 [24]:
data=np.loadtxt('yearssn.dat')
ssc=data[:,1]
year=data[:,0]
In [14]:
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 [65]:
f=plt.figure(figsize=(25,4))
plt.plot(year,ssc)
plt.title("Sun Spots Seen Per Year Since 1700")
plt.xlabel("Year")
plt.ylabel("Number of Sun Spots Seen")
plt.xlim(1700,2015)
plt.ylim(0,180)
Out[65]:
In [ ]:
assert True # leave for grading
Describe the choices you have made in building this visualization and how they make it effective.
I made the figure extra long, relative to its height, in order to accomodate the long range of data in the x direction. I also chose the x and y limits so as to show all of the data. The axis labels and titles are concise and show all of the information needed.
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 [66]:
# YOUR CODE HERE
f=plt.figure(figsize=(25,4))
seventeen=data[:100,:]
eighteen=data[100:200,:]
nineteen=data[200:300,:]
two=data[300:,:]
plt.subplot(2,2,1)
plt.plot(seventeen[:,0],seventeen[:,1])
plt.title("Sun Spots seen per Year During the 1700's")
plt.subplot(2,2,2)
plt.plot(eighteen[:,0],eighteen[:,1])
plt.title("Sun Spots seen per Year During the 1800's")
plt.subplot(2,2,3)
plt.plot(nineteen[:,0],nineteen[:,1])
plt.title("Sun Spots seen per Year During the 1900's")
plt.subplot(2,2,4)
plt.plot(two[:,0],two[:,1])
plt.title("Sun Spots seen per Year During the 2000's")
plt.tight_layout()
In [ ]:
assert True # leave for grading