<jupyter_start><jupyter_text>Seaborn: lineplot<jupyter_code>import seaborn as sns
from matplotlib import pyplot as plt

import pandas as pd<jupyter_output><empty_output><jupyter_text>Grab parking data from [UCI resource](https://archive.ics.uci.edu/ml/datasets/Parking+Birmingham) with Bash commands and read in as `pandas` DataFrame.<jupyter_code>!wget https://archive.ics.uci.edu/ml/machine-learning-databases/00482/dataset.zip
!unzip dataset.zip
df = pd.read_csv('dataset.csv', parse_dates=[3])
df.head()<jupyter_output><empty_output><jupyter_text>Do a bit of data cleaning: - Rename some columns - Create three new date/time columns for later aggregations- Filter down to only two garage locations<jupyter_code>df.rename(columns={'SystemCodeNumber': 'Location', 'LastUpdated': 'Timestamp'}, inplace=True)
df['Day'] = df.Timestamp.dt.date
df['Month'] = df.Timestamp.dt.month
df['Hour'] = df.Timestamp.dt.hour
park = df[df.Location.isin(['Broad Street', 'NIA South'])]
park.head()<jupyter_output><empty_output><jupyter_text>Intro Visuals<jupyter_code>blue, orange, green, red = sns.color_palette()[:4]
sns.set_style('white')
plt.rc('xtick', labelsize=14)
plt.rc('ytick', labelsize=14)
plt.rc('date.autoformatter', day='%b %Y')
months = [pd.datetime(2016, 10, 1), pd.datetime(2016, 11, 1), pd.datetime(2016, 12, 1)];
plt.figure(figsize=(10,6))
sns.lineplot(park.Day, park.Occupancy, ci=None)
plt.xticks(months)
plt.yticks([])
plt.xlim(None, pd.datetime(2016, 12, 1))
plt.ylim(0, 570)
sns.despine(left=True)
plt.xlabel('')
plt.ylabel('')
plt.tight_layout();
plt.figure(figsize=(10,6))
sns.lineplot(park.Day, park.Occupancy)
plt.xticks(months)
plt.yticks([])
plt.xlim(None, pd.datetime(2016, 12, 1))
plt.ylim(0, 570)
sns.despine(left=True)
plt.xlabel('')
plt.ylabel('')
plt.tight_layout();
plt.figure(figsize=(10,6))
sns.lineplot(park.Day, park.Occupancy, hue=park.Location, palette=['gray', 'purple'])
plt.xticks(months)
plt.yticks([])
plt.xlim(None, pd.datetime(2016, 12, 1))
sns.despine(left=True)
plt.xlabel('')
plt.ylabel('')
plt.legend([], frameon=False)
plt.tight_layout();
plt.rc('date.autoformatter', day='%b 1st')
plt.figure(figsize=(6,4))
sns.lineplot(park.Day, park.Occupancy)
plt.xticks(months)
plt.yticks([])
plt.xlim(pd.datetime(2016, 10, 30), pd.datetime(2016, 11, 6))
sns.despine(left=True)
plt.ylim(0, 600)
plt.xlabel('')
plt.ylabel('')
plt.tight_layout();
plt.rc('date.autoformatter', day='%b 1st')
plt.figure(figsize=(6,4))
sns.lineplot(park.Day, park.Occupancy, ci=None)
plt.xticks(months)
plt.yticks([])
plt.xlim(pd.datetime(2016, 10, 30), pd.datetime(2016, 11, 6))
plt.ylim(0, 600)
sns.despine(left=True)
plt.xlabel('')
plt.ylabel('')
plt.tight_layout();
plt.rc('xtick', labelsize=10)
plt.rc('ytick', labelsize=10)<jupyter_output><empty_output><jupyter_text>Basics<jupyter_code>sns.set_style('dark')
months = [pd.datetime(2016, 10, 1), 
          pd.datetime(2016, 11, 1), 
          pd.datetime(2016, 12, 1)]
plt.rc('date.autoformatter', day='%b %Y');
sns.lineplot(park.Day, park.Occupancy)
plt.xticks(months);
sns.lineplot(park.Hour, park.Occupancy);
sns.lineplot(x='Hour', y='Occupancy', data=park);<jupyter_output><empty_output><jupyter_text>Bootstrapping<jupyter_code>sns.lineplot(x='Hour', y='Occupancy', data=park,
             n_boot=1000 
            );<jupyter_output><empty_output><jupyter_text>Decreasing the number of bootstrap samples will increase variance of confidence intervals.<jupyter_code>sns.lineplot(x='Hour', y='Occupancy', data=park,
             n_boot=10
            );
sns.lineplot(x='Hour', y='Occupancy', data=park,
             ci=95
            );
sns.lineplot(x='Hour', y='Occupancy', data=park,
             ci=68
            );<jupyter_output><empty_output><jupyter_text>To turn off the bootstrapped confidence intervals, set `ci=None` to trigger early exit within Seaborn code.  (A conditional checks for this case and completely bypasses the bootstrapping procedure if `ci` is set to `None`.  This saves time if confidence intervals are not needed!)<jupyter_code>sns.lineplot(x='Hour', y='Occupancy', data=park,
             ci=None
            );
sns.lineplot(x='Hour', y='Occupancy', data=park,
             estimator='mean'
            );
sns.lineplot(x='Hour', y='Occupancy', data=park,
             estimator='sum'
            );
sns.lineplot(x='Hour', y='Occupancy', data=park,
             estimator='std'
            );<jupyter_output><empty_output><jupyter_text>Visual Semantics  hue<jupyter_code>sns.lineplot(x='Day', y='Occupancy', data=park, hue='Location')

plt.xticks(months);
sns.lineplot(x='Day', y='Occupancy', data=park, 
             hue='Location',
             palette = ['gray', 'xkcd:brick red']
            )

plt.xticks(months);<jupyter_output><empty_output><jupyter_text>style<jupyter_code>sns.lineplot(x='Day', y='Occupancy', data=park, style='Location')

plt.xticks(months);
sns.lineplot(x='Day', y='Occupancy', data=park,
             hue="Location",
             style='Location'
            )

plt.xticks(months);<jupyter_output><empty_output><jupyter_text>size<jupyter_code>sns.lineplot(x='Hour', y='Occupancy', data=park, size='Location',
            );
sns.lineplot(x='Hour', y='Occupancy', data=park, ci=None,
             size='Month'
            );<jupyter_output><empty_output><jupyter_text>Style Most of matplotlib's line styling works within the Seaborn lineplot.  (The main exception is that `linestyle` does not work.)<jupyter_code>sns.lineplot(x='Day', y='Occupancy', data=park, ci=None, 
             lw=4,
             color='#aa00aa',
             alpha=0.5
            )

plt.xticks(months);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17273858183756888, 'fraction_numerical': 0.02736804691665186, 'mean_word_length': 4.974522292993631, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 2, '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': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '649468', 'license': 'MIT', 'n_tokens_mistral': 2323, 'n_tokens_neox': 2115, 'n_words': 358, 'path': '09_lineplot.ipynb', 'repo_name': 'AdarshAnand67/Seaborn-Complete', 'size': '5627'}