<jupyter_start><jupyter_text>ASSIGNMENT 1) Replicate the lesson code. I recommend that you [do not copy-paste](https://docs.google.com/document/d/1ubOw9B3Hfip27hF2ZFnW3a3z9xAgrUDRReOEo-FHCVs/edit).Get caught up to where we got our example in class and then try and take things further. How close to "pixel perfect" can you make the lecture graph?Once you have something that you're proud of, share your graph in the cohort channel and move on to the second exercise. 2) Reproduce another example from [FiveThityEight's shared data repository](https://data.fivethirtyeight.com/).**WARNING**: There are a lot of very custom graphs and tables at the above link. I **highly** recommend not trying to reproduce any that look like a table of values or something really different from the graph types that we are already familiar with. Search through the posts until you find a graph type that you are more or less familiar with: histogram, bar chart, stacked bar chart, line chart, [seaborn relplot](https://seaborn.pydata.org/generated/seaborn.relplot.html), etc. Recreating some of the graphics that 538 uses would be a lot easier in Adobe photoshop/illustrator than with matplotlib. - If you put in some time to find a graph that looks "easy" to replicate you'll probably find that it's not as easy as you thought. - If you start with a graph that looks hard to replicate you'll probably run up against a brick wall and be disappointed with your afternoon.<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import AutoMinorLocator, MultipleLocator, FuncFormatter
from IPython.display import display, Image

url = 'https://fivethirtyeight.com/wp-content/uploads/2017/09/mehtahickey-inconvenient-0830-1.png'
example = Image(url=url, width=400)

display(example)
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

fake = pd.Series([38, 3, 2, 1, 2, 4, 6, 5, 5, 33],
                  index=range(1,11))

fake.plot.bar(color='C1', width=0.9);
fake2 = pd.Series(
    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
     2, 2, 2, 
     3, 3, 3,
     4, 4,
     5, 5, 5,
     6, 6, 6, 6,
     7, 7, 7, 7, 7,
     8, 8, 8, 8,
     9, 9, 9, 9, 
     10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10])

ax = fake2.value_counts().sort_index().plot.bar(color='C1', width=0.9);
  
ax.grid(True)
# From lesson

import matplotlib.pyplot as plt

plt.style.use('fivethirtyeight')

fig = plt.figure()
fig.patch.set(facecolor='white')

ax = fake.plot.bar(color="#ED713A", width=0.9)
ax.set(facecolor='white')

ax.text(x=-1.8, y=44, s="'An Inconvenient Sequel: Truth To Power' is divisive",
        fontweight='bold', fontsize=12);
ax.text(x=-1.8, y=41.5, s="IMDb ratings for the film as of Aug. 29", 
        fontsize=11)

ax.set_ylabel("Percent of total votes", fontsize=9, fontweight='bold', 
              labelpad=10)
ax.set_xlabel("Rating", fontsize=9, fontweight='bold', labelpad=10)

ax.set_xticklabels(range(1,11), rotation=0)
ax.set_yticks(range(0,50,10))
ax.set_yticklabels(range(0, 50, 10))

plt.show()
display(example)
import matplotlib.pyplot as plt

plt.style.use('fivethirtyeight')

fig = plt.figure(figsize=(5.47,3.75))
fig.patch.set(facecolor='white')

plt.rcParams["font.family"] = "Atlas Grotesk"

ax = fake.plot.bar(color="#ED713A", width=0.9)
ax.set(facecolor='white')

ax.set_ylim(bottom=-1.5)
ax.set_ylim(top=40.5)

ax.text(x=-1.8, y=46, s="'An Inconvenient Sequel: Truth To Power' is divisive",
        fontweight='bold', fontsize=12);
ax.text(x=-1.8, y=43.5, s="IMDb ratings for the film as of Aug. 29", 
        fontsize=11)

ax.set_ylabel("Percent of total votes", fontsize=9.7, fontweight='bold', 
              labelpad=10, fontname="Atlas Grotesk")
ax.set_xlabel("Rating", fontsize=9.7, fontweight='bold', labelpad=10)

ax.set_xticklabels(range(1,11), rotation=0)
yt1 = [0,10,20,30,40]
yt2 = ['0  ', '10  ', '20  ', '30  ', '40%']
ax.set_yticks(yt1)
ax.set_yticklabels(yt2)

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_visible(False)

ax.tick_params(labelsize=9.42, grid_alpha=0.75, labelcolor = '#bfbfbf')

plt.show()
display(example)
url2 = 'https://fivethirtyeight.com/wp-content/uploads/2015/04/barry-jester-datalab-boomersdruguse-actual.png?w=575'
example2 = Image(url=url2, width=400)

display(example2)
df = pd.read_csv('https://raw.githubusercontent.com/fivethirtyeight/data/master/drug-use-by-age/drug-use-by-age.csv')
df.round(2)
df.tail(5)
boomer_drug = df.loc[[15]]
boomer_drug
boomer_drug.drop([col for col in df.columns if 'frequency' in col],axis=1,inplace=True)
boomer_drug
boomer_drug.drop('alcohol-use', axis=1, inplace=True)
boomer_drug
boomer_drug = boomer_drug.T
boomer_drug
boomer_drug = boomer_drug.drop(['age', 'n'])
boomer_drug
boomer_drug.rename(index = {'marijuana-use': 'Marijuana',
                            'cocaine-use': 'Cocaine',
                            'crack-use': 'Crack',
                            'heroin-use': 'Heroin',
                            'hallucinogen-use': 'Hallucinogen',
                            'inhalant-use': 'Inhalant',
                            'pain-releiver-use': 'Pain reliever',
                            'oxycontin-use': 'OxyContin',
                            'tranquilizer-use': 'Tranquilizer',
                            'stimulant-use': 'Stimulant',
                            'meth-use': 'Meth',
                            'sedative-use': 'Sedative'},
                                         inplace = True)
boomer_drug
boomer_drug.columns = boomer_drug.columns.astype(str)
boomer_drug
boomer_drug = boomer_drug.sort_values(by=['15'])
boomer_drug 
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')

fig = plt.figure(figsize=(5.47,3.75))
fig.patch.set(facecolor='white')

ax = boomer_drug.plot.barh(color='r', width=0.9)
ax.set(facecolor='white')

ax.text(x=-2, y=12.2, s="Percentage of Americans aged 50-64 who said in a 2012 survey \n that they had used the following drugs in the past year",
        fontsize=14);

y = [0.05, 0.15, 0.15, 0.23 ,0.25, 0.28, 0.36, 0.36, 0.87, 1.43, 2.52, 7.29]

for i, v in enumerate(y):
    ax.text(v + 0.15, i + -0.18, str(v), color='black', size='12')

ax.grid(False)

ax.axes.get_xaxis().set_visible(False)

ax.get_legend().remove()

plt.show();
display(example2)
# Order of values are different because the data 538 used for their plot was with 2 decimal points,
# but the data they uploaded on github only uses 1 decimal place.
# I am fairly certain I put in the code for facecolor correctly, but the background color will not change from gray.
# Unsure about how to add a % next to 7.29 without breaking the code, gives errors when I try to.<jupyter_output><empty_output><jupyter_text>STRETCH OPTIONS 1) Reproduce one of the following using the matplotlib or seaborn libraries:- [thanksgiving-2015](https://fivethirtyeight.com/features/heres-what-your-part-of-america-eats-on-thanksgiving/) - [candy-power-ranking](https://fivethirtyeight.com/features/the-ultimate-halloween-candy-power-ranking/) - or another example of your choice! 2) Make more charts!Choose a chart you want to make, from [Visual Vocabulary - Vega Edition](http://ft.com/vocabulary).Find the chart in an example gallery of a Python data visualization library:- [Seaborn](http://seaborn.pydata.org/examples/index.html)- [Altair](https://altair-viz.github.io/gallery/index.html)- [Matplotlib](https://matplotlib.org/gallery.html)- [Pandas](https://pandas.pydata.org/pandas-docs/stable/visualization.html)Reproduce the chart. [Optionally, try the "<NAME>."](https://docs.google.com/document/d/1ubOw9B3Hfip27hF2ZFnW3a3z9xAgrUDRReOEo-FHCVs/edit) If you want, experiment and make changes.Take notes. Consider sharing your work with your cohort!<jupyter_code># More Work Here<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13767019667170954, 'fraction_numerical': 0.04589006555723651, 'mean_word_length': 3.7904589371980677, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '174689', 'license': 'MIT', 'n_tokens_mistral': 3081, 'n_tokens_neox': 2789, 'n_words': 757, 'path': 'module3-make-explanatory-visualizations/LS_DS_123_Make_Explanatory_Visualizations_Assignment.ipynb', 'repo_name': 'mooglol/DS-Unit-1-Sprint-1-Dealing-With-Data', 'size': '7945'}