<jupyter_start><jupyter_text>Table of Contents  Plotting is a quick way to see patterns and gain insights into your data.Here we will see a few ways to plot things using seaborn and the built-in pandas methods<jupyter_code>import pandas as pd
# use the seaborn plotting library
import seaborn as sns
# load up the anscombe dataset
anscombe = sns.load_dataset('anscombe')
anscombe
# we typically need to tell python to show the plot
# we need matplotlib to make the show call
import matplotlib.pyplot as plt

# this command is called a magic
# this particular magic command tells jupyter to plot the figures under the code chunk
# insead of a popup
%matplotlib inline
# subset the first dataset in the anscombe dataset
data1 = anscombe[anscombe['dataset'] == 'I']
data1.head()
# use matplotlib to plot
# it defaults to a line plot
plt.plot(data1['x'], data1['y'])
plt.show()
# we can pass in the 'o' parameter to plot points
# it's 'o' becuase points literally look like the letter 'o'
plt.plot(data1['x'], data1['y'], 'o')
plt.show()
# Here we create the same figure
# but we are being more explicit with the figure creation and the axes creation
fig = plt.figure()
axes = fig.add_subplot(1, 1, 1)
axes.plot(data1['x'], data1['y'], 'o')
plt.show()
# now we take our full anscombe dataest
# and create a faceted scatter plot using seaborn
sns.lmplot('x', 'y', anscombe, fit_reg=False, col='dataset', col_wrap=2)
# we'll load up a different dataset for more plotting examples
tips = sns.load_dataset('tips')
tips.head()
# a violin plot is like a density plot, that has been mirrored on its axis
# it over emphasizses the distribution so you can see whether your data is left or right skewed
plot, ax = plt.subplots()
ax = sns.violinplot('time', 'total_bill',
                    hue='sex',
                    data=tips)
# again, we can be very explitit in creating the figure and axes objects to plot
# here we also pass in the split argument
# so we cam compare male/female across lunch/dinner times
plot, ax = plt.subplots()
ax = sns.violinplot('total_bill','time',
                    hue='sex', split=True,
                    data=tips)
plt.show()
# when plotting scatterplot with many points,
# it helps to aggregate them so you can better see densities
# hexbin is one way to do this visualization aggregation
fig, ax = plt.subplots()
ax = tips.plot.hexbin('total_bill', 'tip', gridsize=10)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09191629052113254, 'fraction_numerical': 0.005744768157570784, 'mean_word_length': 4.143459915611814, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '527411', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 778, 'n_tokens_neox': 733, 'n_words': 328, 'path': 'class/10-plots.ipynb', 'repo_name': 'chendaniely/2017-10-26-mckinsey', 'size': '2437'}