<jupyter_start><jupyter_text>M2: Basic Graphing Assignment - <NAME><jupyter_code># Import matplotlib and Pandas
import matplotlib.pyplot as plt
import pandas as pd

# Enable in-cell graphs
%matplotlib inline

# Read-in the input files and tore in Data frames
df_opiods = pd.read_csv('OpiodsVA.csv')
df_pres = pd.read_csv('presidents.csv')
df_cars = pd.read_csv('TOTALNSA.csv')<jupyter_output><empty_output><jupyter_text>Problem 1**Question 1:** Do opioid overdoes tend to be associated with less affluent areas? That is, areas wherefamilies have lower incomes?**Answer:** I chose scatter plots for this problem because they are the best at showing relationship between two numerical values.<jupyter_code># Plotting the data and adjusting the apperance of the plots
fig,ax = plt.subplots()

# Setting properties of graph - Opioids ODs vs Median Income
ax.scatter(df_opiods['MedianHouseholdIncome'], df_opiods['FPOO-Rate'],c = 'blue', alpha = 0.5,s = 50)
ax.xaxis.set_label_text('Median Household Income', fontsize = 14)
ax.yaxis.set_label_text('Opioid Overdoses', fontsize = 14)

# Formating the graph using Figure methods
fig.suptitle('Opioid ODs vs Median Income', fontsize = 18)
fig.set_size_inches(8,5)

# Display graph
plt.show()<jupyter_output><empty_output><jupyter_text>**Question 2:** What is the relationship in Virginia counties between opioid overdoses and heroin overdoses?**Answer:** I chose scatter plot for this problem because they are the best at showing relationship between two numerical values.<jupyter_code># Plotting the data and adjusting the apperance of the plots
fig,ax = plt.subplots()

# Setting properties of graph - Opioid ODs vs Heroin ODs
ax.scatter(df_opiods['FPOO-Rate'], df_opiods['FFHO-Rate'], c = 'green', alpha = 0.5,s = 50)
ax.xaxis.set_label_text('Opioid Overdoses', fontsize = 14)
ax.yaxis.set_label_text('Heroin Overdoses', fontsize = 14)

# Formating the graph using Figure methods
fig.suptitle('Opioid ODs vs Heroin ODs', fontsize = 18)
fig.set_size_inches(8,5)

# Display graph
plt.show()<jupyter_output><empty_output><jupyter_text>Problem 2**Question:** Which states are associated with the greatest number of United States presidents in terms of the presidents’ birthplaces?**Answer:** I chose bar graph (or Histogram) since it's the best when comparing frequences of events.<jupyter_code># Counting Values and storing them in a dictionary
stateCounts = dict(df_pres['State'].value_counts())

# Sorting the dictionary by frequency values and storing key/value pairs as sub-tuples
sortedList = sorted(stateCounts.items(), key = lambda x: x[1], reverse = True)

# storing sorted values in x and y
x = [state for [state,freq] in sortedList]
y = [freq for [state,freq] in sortedList]

# Plotting the data and adjusting the apperance of the plots
fig, ax = plt.subplots()

# Setting properties of axes
ax.bar(x = x,height = y, color = 'blue', alpha = 0.75)
ax.yaxis.set_label_text('Number of Presidents', fontsize = 14)
ax.xaxis.set_label_text('States', fontsize = 14)
plt.xticks(rotation = 90)

# Setting properties of the graph
fig.suptitle('Presidents Birthplace State Frequency Histogram', fontsize = 18)
fig.set_size_inches(10,5)

# Display graph
plt.show()<jupyter_output><empty_output><jupyter_text>Problem 3**Question:** How have vehicle sales in the United States varied over time?**Answer:** I chose a line graph since they are the best at showing changes over periods of time (timelines).<jupyter_code># Plotting the data and adjusting the apperance of the plots
fig,ax = plt.subplots()

# Setting properties of the graph - Car Sales Overtime
ax.plot(df_cars['DATE'], df_cars['TOTALNSA'],c = 'blue')
ax.xaxis.set_label_text('Date', fontsize = 14)
ax.yaxis.set_label_text('Car Sales', fontsize = 14)
ax.xaxis.set_major_locator(plt.MaxNLocator(50)) # displaying 1 tick per year
plt.xticks(rotation = 90)

# Formating the graph using Figure methods
fig.suptitle('US Car Sales', fontsize = 18)
fig.set_size_inches(16,5)

# Display graph
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10407352210630899, 'fraction_numerical': 0.014654744162940884, 'mean_word_length': 5.991319444444445, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '6048', 'license': 'CC0-1.0', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1290, 'n_words': 431, 'path': 'Jupyter/BasicGraphAssignment.ipynb', 'repo_name': 'denis83/denis83.github.io', 'size': '4033'}