<jupyter_start><jupyter_text>Data Visualization in PythonIn this example, we will be plotting the COVID case rate by the vaccination rates for U.S. states and territories.We start by importing additional packages necessary for this visualization.<jupyter_code>import pandas
import seaborn

print("Packages loaded!")<jupyter_output><empty_output><jupyter_text>Next, we load data and look at the first few rows.<jupyter_code>covid = pandas.read_csv("data/COVID_Data.csv")
covid.head()<jupyter_output><empty_output><jupyter_text>Our first plot will be plotting the case rate per 100,000 people vs. the percentage of people who have received at least one dose. Using the seaborn method `regplot`, it will automatically draw the line from linear regression.<jupyter_code>seaborn.regplot(x = "One_Dose", y = "Case_Rate", data = covid)<jupyter_output><empty_output><jupyter_text>We should update our axis labels, using the `set` command. Note here we also assigned the plot to a variable (`covid_plot`), so we could manipulate it.<jupyter_code>covid_plot = seaborn.regplot(x = "One_Dose", y = "Case_Rate", data = covid)
covid_plot.set(xlabel = "Percentage with at least one dose", ylabel = "Cases (per 100K)")<jupyter_output><empty_output><jupyter_text>Next, we will modify our code to change what we plot on the x-axis. In this case we want to plot Dose_Rate on the x-axis. Update the code below to change the values we are plotting on the x-axis.<jupyter_code>covid_plot = seaborn.regplot(x = "One_Dose", y = "Case_Rate", data = covid)<jupyter_output><empty_output><jupyter_text>By default, it will add a linear regression line and confidence intervals. This does not look like a linear relationship (the case rate doesn't appear to increase continuously with vaccination rate). Try a polynomial relationship by adding `order = 2` to the `regplot` method (immediately following the data specification).<jupyter_code># Paste your code from above here, and update<jupyter_output><empty_output><jupyter_text>Maybe a little better, but a 3-order polynomial works best. Change the order specification, replacing the `2` with `3` in the `order` argument.<jupyter_code># Paste your code from the previous code block and update<jupyter_output><empty_output><jupyter_text>To finish off this plot, we want to:1. Update the axis labels to be readable and include units in parentheses2. Write the plot to a png file<jupyter_code>vaccination_plot = # Copy and paste the plot code from the code block above
vaccination_plot.set(xlabel = "<UPDATE>", ylabel = "<UPDATE>") # Replace <UPDATE> with appropriate labels
# Saves the plot to vaccination-cases.png
vaccination_plot.get_figure().savefig("vaccination-cases.png")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08321114369501466, 'fraction_numerical': 0.005498533724340176, 'mean_word_length': 6.2387267904509285, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '173538', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 841, 'n_tokens_neox': 800, 'n_words': 316, 'path': 'intro-covid-seaborn.ipynb', 'repo_name': 'jcoliver/data-viz-roadshow', 'size': '2728'}