In [4]:
%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 [5]:
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 [6]:
data = np.loadtxt('yearssn.dat')
years = data[::1,0]
ssc = data[::1,1]
In [7]:
assert len(years)==315
assert years.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 [8]:
fig = plt.figure(figsize=(150,10))
plt.plot(years, ssc)
plt.title('Sun Spot Count vs. Time')
plt.xlabel('Time(years)')
plt.ylabel('Sun Spot Count')
plt.tick_params(top = False, right=False)
plt.xlim(1700.5, 2015)
Out[8]:
In [9]:
assert True # leave for grading
Describe the choices you have made in building this visualization and how they make it effective.
With the requirement of the maximum slope, using just one graph is not effective for this particular data set. The aspect ratio makes the graph unreadable without zooming in a lot. However, creating four seperate graphs below creates a much better visualization. Sharing the y-axis scaling and titles horizontally make the graphs simpler, as well as sharing the x-axis title vertically.
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 [10]:
f, ax = plt.subplots(2,2, sharey=True, figsize=(25,7))
for n in range(1,5):
plt.subplot(2,2,n)
plt.tick_params(top=False, right=False)
plt.tight_layout()
for m in range(1,5):
if m % 2 != 0:
plt.subplot(2,2,m)
plt.ylabel('Sun Spot Count')
if m == 3 or m == 4:
plt.subplot(2,2,m)
plt.xlabel('Time')
plt.subplot(2,2,1)
plt.plot(years[0:101:1], ssc[0:101:1])
plt.xlim(1700.5, 1800.5)
plt.ylim(0,200)
plt.title('Sun Spot Count vs. Time')
plt.subplot(2,2,2)
plt.plot(years[100:201:1], ssc[100:201:1])
plt.xlim(1800.5, 1900.5)
plt.ylim(0,200)
plt.tick_params(labelleft=False)
plt.subplot(2,2,3)
plt.plot(years[200:301:1], ssc[200:301:1])
plt.xlim(1900.5,2000.5)
plt.ylim(0,200)
plt.subplot(2,2,4)
plt.plot(years[300:315:1], ssc[300:315:1])
plt.xlim(2000.5, 2015)
plt.ylim(0,200)
plt.tick_params(labelleft=False)
plt.tight_layout()
In [ ]:
assert True # leave for grading