In [41]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import math
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 [15]:
data = np.array(np.loadtxt('yearssn.dat'))
year = data[:,0]
ssc = data[:,1]
#raise NotImplementedError()
In [16]:
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]:
ticks = np.arange(year.min(), year.max(), 10)
f = plt.figure(figsize=(30,1))
plt.plot(year, ssc, 'b.-');
plt.xlim(year.min() - 5, year.max() + 5);
plt.xticks(ticks, [str(int(x)) for x in ticks]);
plt.xlabel("Year")
plt.ylabel("Mean Total Sunspots")
plt.title("Mean Total Sunspots vs. Year")
#raise NotImplementedError()
Out[69]:
In [ ]:
assert True # leave for grading
Describe the choices you have made in building this visualization and how they make it effective.
I haven't altered much. The aspect ratio to effect a maximum slope of 1 was hard to achieve. I could have taken the borders of the box off the top and right. I liked blue and decided to use points with lines so that it was clear how fine the temporal resolution is. I labeled every 10 years so that the x-axis labels were not crowded but also not sparse. All other labels describe the plot.
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 [95]:
cents = np.array([int(x / 100) for x in year])
ucents = np.unique(cents)
f, ax = plt.subplots(2, 2, sharey = True, figsize = (12, 1))
for i in range(2):
for j in range(2):
subyr = np.array([year[x] for x in range(len(year)) if cents[x] == ucents[2*i + j]])
subspots = [ssc[x] for x in range(len(year)) if cents[x] == ucents[2*i + j]]
subticks = np.arange(subyr.min(), subyr.max(), 10)
plt.sca(ax[i,j])
plt.plot(subyr, subspots, "b.-")
plt.xlim(subyr.min() - 5, subyr.max() + 5);
plt.xticks(subticks, [str(int(x)) for x in subticks]);
plt.xlabel("Year")
plt.ylabel("Mean Total Sunspots")
plt.title("Mean Total Sunspots vs. Year")
plt.subplots_adjust(hspace = 1.5, bottom = 0.05, top = 2.25)
#raise NotImplementedError()
In [ ]:
assert True # leave for grading