In [74]:
%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 [75]:
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 [76]:
data = np.loadtxt('yearssn.dat')
year = data[:,0]
ssc = data[:,1]
In [77]:
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 [78]:
plt.figure(figsize=(50,5))
plt.plot(year, ssc)
plt.grid(True)
plt.yticks([50,100,150,200], [50,100,150,200])
plt.xticks([1700,1750,1800,1850,1900,1950,2000], [1700,1750,1800,1850,1900,1950,2000])
plt.xlabel('Year')
plt.ylabel('Sun Spot Count')
plt.title('Sun Spot Counts per Year 1700-Now')
Out[78]:
In [79]:
assert True # leave for grading
Describe the choices you have made in building this visualization and how they make it effective.
YOUR ANSWER HERE
First I streched the graph way out horizontally to lessen the slope, making the data easier to read. I then labeled each axis and gave the graph a title, because not doing so is crazy talk. Then I altered what 'ticks' show up, as only certain values are important to what this graph is trying to show.
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 [103]:
year
year_1st=year[0:100]
year_2nd=year[101:200]
year_3rd=year[201:300]
year_4th=year[301:400]
ssc_1st=ssc[0:100]
ssc_2nd=ssc[101:200]
ssc_3rd=ssc[201:300]
ssc_4th=ssc[301:400]
plt.figure(figsize=(30,10))
plt.subplot(4,1,1)
plt.title('Sun Spot Counts per Year')
plt.plot(year_1st, ssc_1st)
plt.tight_layout()
plt.yticks([50,100,150,200], [50,100,150,200])
plt.ylabel('Sun Spot Count')
plt.subplot(4,1,2)
plt.plot(year_2nd, ssc_2nd)
plt.tight_layout()
plt.yticks([50,100,150,200], [50,100,150,200])
plt.ylabel('Sun Spot Count')
plt.subplot(4,1,3)
plt.plot(year_3rd, ssc_3rd)
plt.tight_layout()
plt.yticks([50,100,150,200], [50,100,150,200])
plt.ylabel('Sun Spot Count')
plt.subplot(4,1,4)
plt.plot(year_4th, ssc_4th)
plt.tight_layout()
plt.yticks([50,100,150,200], [50,100,150,200])
plt.xlabel('Year')
plt.ylabel('Sun Spot Count')
Out[103]:
In [91]:
assert True # leave for grading
In [ ]: