%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

"""
Explanation: Matplotlib Exercise 1
Imports
End of explanation
"""


import os
assert os.path.isfile('yearssn.dat')

"""
Explanation: Line plot of sunspot data
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.
End of explanation
"""


data=np.loadtxt('yearssn.dat')

year = data[:,0]
ssc = data[:,1]

assert len(year)==315
assert year.dtype==np.dtype(float)
assert len(ssc)==315
assert ssc.dtype==np.dtype(float)

"""
Explanation: 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.
End of explanation
"""


f = plt.figure(figsize=(10,5))
plt.plot(year,ssc)
plt.xlabel('Year')
plt.ylabel('Sunspot Count')
plt.xlim(1700, 2015)
plt.ylim(0, 200)
plt.tick_params(axis='y', direction='out', length=5)
plt.box(False)


assert True # leave for grading

"""
Explanation: Make a line plot showing the sunspot count as a function of year.

Customize your plot to follow Tufte's principles of visualizations.
Adjust the aspect ratio/size so that the steepest slope in your plot is approximately 1.
Customize the box, grid, spines and ticks to match the requirements of this data.
End of explanation
"""


x = plt.figure(figsize=(15,15))

plt.subplot(4,1,1) 
plt.plot(year[0:99], ssc[0:99])
plt.ylabel("Sunspot Count")
plt.box(False)

plt.subplot(4,1,2)
plt.plot(year[100:199], ssc[100:199])
plt.box(False)

plt.subplot(4,1,3)
plt.plot(year[200:299], ssc[200:299])
plt.box(False)

plt.subplot(4,1,4)
plt.plot(year[300:], ssc[300:])
plt.xlabel("Year")
plt.box(False)

plt.tight_layout()

assert True # leave for grading

"""
Explanation: Describe the choices you have made in building this visualization and how they make it effective.
I made my plot longer in the horizontal direction in order to make the years more discernable.  I labeled the plot so that my data is understandable.  I changed the limits of my axes so that the data fills the chart.  I also changed the directions of the y ticks to the outside so they don't overlap onto my line.
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:

Customize your plot to follow Tufte's principles of visualizations.
Adjust the aspect ratio/size so that the steepest slope in your plot is approximately 1.
Customize the box, grid, spines and ticks to match the requirements of this data.
End of explanation
"""


