<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Matplotlib Exercise 1
Imports
Step1:  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.
Step2:  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.
Step3:  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.
Step4:  Describe the choices you have made in building this visualization and how they make it effective.
I made the figure extra long, relative to its height, in order to accomodate the long range of data in the x direction. I also chose the x and y limits so as to show all of the data. The axis labels and titles are concise and show all of the information needed.
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
<ASSISTANT_TASK:>
Python Code:
%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')
ssc=data[:,1]
year=data[:,0]
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=(25,4))
plt.plot(year,ssc)
plt.title("Sun Spots Seen Per Year Since 1700")
plt.xlabel("Year")
plt.ylabel("Number of Sun Spots Seen")
plt.xlim(1700,2015)
plt.ylim(0,180)
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
# YOUR CODE HERE
f=plt.figure(figsize=(25,4))
seventeen=data[:100,:]
eighteen=data[100:200,:]
nineteen=data[200:300,:]
two=data[300:,:]
plt.subplot(2,2,1)
plt.plot(seventeen[:,0],seventeen[:,1])
plt.title("Sun Spots seen per Year During the 1700's")
plt.subplot(2,2,2)
plt.plot(eighteen[:,0],eighteen[:,1])
plt.title("Sun Spots seen per Year During the 1800's")
plt.subplot(2,2,3)
plt.plot(nineteen[:,0],nineteen[:,1])
plt.title("Sun Spots seen per Year During the 1900's")
plt.subplot(2,2,4)
plt.plot(two[:,0],two[:,1])
plt.title("Sun Spots seen per Year During the 2000's")
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 the figure extra long, relative to its height, in order to accomodate the long range of data in the x direction. I also chose the x and y limits so as to show all of the data. The axis labels and titles are concise and show all of the information needed.
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
<END_TASK>