<jupyter_start><jupyter_text>Matplotlib Exercise 1  Imports<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np<jupyter_output><empty_output><jupyter_text>Line plot of sunspot data Download the `.txt` data for the "Yearly mean total sunspot number [1700 - now]" from the [SILSO](http://www.sidc.be/silso/datafiles) website. Upload the file to the same directory as this notebook.<jupyter_code>import os
assert os.path.isfile('yearssn.dat')<jupyter_output><empty_output><jupyter_text>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.<jupyter_code># YOUR CODE HERE
data = np.loadtxt("yearssn.dat")
year = data[:,0]
ssc = data[:,1]
print(year)
print(ssc)
assert len(year)==315
assert year.dtype==np.dtype(float)
assert len(ssc)==315
assert ssc.dtype==np.dtype(float)<jupyter_output><empty_output><jupyter_text>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.<jupyter_code># YOUR CODE HERE
#http://matplotlib.org/examples/pylab_examples/spine_placement_demo.html
fig = plt.figure(figsize=(12,1))
ax = fig.add_subplot(1, 1, 1)
ax.set_title("Sunspot Activity")
ax.plot(year, ssc)

plt.xlabel("Year")
plt.ylabel("Sunspot Count")
ax.grid(True)
ax.spines["right"].set_visible(False)
ax.spines["top"].set_visible(False)
assert True # leave for grading<jupyter_output><empty_output><jupyter_text>Describe the choices you have made in building this visualization and how they make it effective. The default color and line style worked well for the data, so I didn't change those. I adjusted the aspect ratio of the graph to get a reasonable slope, as per the instructions. I also added labels, and removed the upper and right spines. 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.<jupyter_code>print(year[0:100])
print(len(year[0:100]))
print(len(ssc[0:100]))
# YOUR CODE HERE
fig, ax = plt.subplots(4, 1, figsize=(12,12))

plt.sca(ax[0])
plt.plot(year[0:100], ssc[0:100])
plt.ylabel("Sunspots")
plt.xlabel("Year")

plt.sca(ax[1])
plt.plot(year[100:200], ssc[100:200])
plt.ylabel("Sunspots")
plt.xlabel("Year")

plt.sca(ax[2])
plt.plot(year[200:300], ssc[200:300])
plt.ylabel("Sunspots")
plt.xlabel("Year")

plt.sca(ax[3])
plt.plot(year[300:-1], ssc[300:-1])
plt.ylabel("Sunspots")
plt.xlabel("Year")
plt.xlim([2000, 2100])
assert True # leave for grading<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup