<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
f = np.loadtxt('yearssn.dat')
data = np.array(f)
split = np.hsplit(data, 2)
flat = np.ravel(split)
year = flat[0:315:1]
ssc = flat[315::]
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
f = plt.figure(figsize=(27,6))
fig = plt.plot(year, ssc)
ax = plt.gca()
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.get_xaxis().tick_bottom()
ax.get_yaxis().tick_left()
plt.xlabel('Years')
plt.ylabel('Sun Spot Count')
plt.title('Sunspots over the years')
plt.xlim(1700, 2020)
plt.tick_params(axis='y', direction='out', length=10)
plt.grid()
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. YOUR ANSWER HERE: I lowered the aspect ratio so that the lines appear less steep.  I also removed the top and right hand spines and tick marks to make it less cluttered looking on the sides, and added grid lines to help follow the data. 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># YOUR CODE HERE
f = plt.figure(figsize=(15,9))


plt.subplot(2, 2, 1)
plt.plot(year[0:100], ssc[0:100])
plt.xlabel('Years')
plt.ylabel('Sun Spot Count')
plt.title('Sunspots over the 1700\'s')
ax = plt.gca()
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.get_xaxis().tick_bottom()
ax.get_yaxis().tick_left()
plt.grid()

plt.subplot(2, 2, 2)
plt.plot(year[101:200], ssc[101:200])
plt.xlabel('Years')
plt.ylabel('Sun Spot Count')
plt.title('Sunspots over the 1800\'s')
ax = plt.gca()
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.get_xaxis().tick_bottom()
ax.get_yaxis().tick_left()
plt.grid()

plt.subplot(2, 2, 3)
plt.plot(year[201:300], ssc[201:300])
plt.xlabel('Years')
plt.ylabel('Sun Spot Count')
plt.title('Sunspots over the 1900\'s')
ax = plt.gca()
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.get_xaxis().tick_bottom()
ax.get_yaxis().tick_left()
plt.grid()

plt.subplot(2, 2, 4)
plt.plot(year[300:320], ssc[300:320])
plt.xlabel('Years')
plt.ylabel('Sun Spot Count')
plt.title('Sunspots til now')
ax = plt.gca()
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.get_xaxis().tick_bottom()
ax.get_yaxis().tick_left()

plt.tight_layout()
plt.grid()
assert True # leave for grading<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13306451612903225, 'fraction_numerical': 0.02721774193548387, 'mean_word_length': 6.0875, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '106984', 'license': 'MIT', 'n_tokens_mistral': 1494, 'n_tokens_neox': 1366, 'n_words': 413, 'path': 'assignments/assignment04/MatplotlibEx01.ipynb', 'repo_name': 'enbanuel/phys202-2015-work', 'size': '3968'}