In [39]:
%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 [40]:
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 [41]:
data = np.loadtxt('yearssn.dat','float')
year = np.array(range(len(data)),'float')
ssc = np.array(range(len(data)),'float')
for x in range(len(data)):
year[x] = data[x,0]
ssc[x] = data[x,1]
In [42]:
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 [43]:
plt.figure(figsize=(18,1))
plt.plot(year,ssc)
plt.xlabel('Year')
plt.ylabel('Mean Sunspot \n Number')
plt.title('Sunspot Data from 1700-2014')
plt.xlim(1700.0, 2015.0)
plt.ylim(0, 200)
plt.yticks([100,200])
Out[43]:
In [44]:
assert True # leave for grading
Describe the choices you have made in building this visualization and how they make it effective.
I picked this style of graphing because in the directions you asked for a max slope of about 1, also I picked an amount of minimum amount of rick marks for the graph to still be readable.
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 [45]:
plt.figure(figsize=(13,8))
plt.subplot(4,1,1)
plt.plot(year,ssc)
plt.xlabel('Year')
plt.ylabel('Mean Sunspot \n Number')
plt.title('Sunspot Data from 1700-2014')
plt.xlim(1700.0, 1800.0)
plt.ylim(0, 200)
plt.yticks([100,200])
plt.subplot(4,1,2) # 2 rows x 1 col, plot 2
plt.plot(year,ssc)
plt.xlabel('Year')
plt.ylabel('Mean Sunspot \n Number')
plt.xlim(1800.0, 1900.0)
plt.ylim(0, 200)
plt.yticks([100,200])
plt.subplot(4,1,3) # 2 rows x 1 col, plot 2
plt.plot(year,ssc)
plt.xlabel('Year')
plt.ylabel('Mean Sunspot \n Number')
plt.xlim(1900.0, 2000.0)
plt.ylim(0, 200)
plt.yticks([100,200])
plt.subplot(4,1,4) # 2 rows x 1 col, plot 2
plt.plot(year,ssc)
plt.xlabel('Year')
plt.ylabel('Mean Sunspot \n Number')
plt.xlim(2000.0, 2015.0)
plt.ylim(0, 200)
plt.yticks([100,200])
plt.tight_layout()
In [46]:
assert True # leave for grading