Skip to main content

Stub 1 (Python Libraries)

  • Page ID

    To compare multiple attributes with one another, use a scatterplot matrix.

    %matplotlib inline
    import seaborn as sns
    df = sns.load_dataset("iris")
    sns.pairplot(df, hue="species")
    <seaborn.axisgrid.PairGrid at 0x7f97d574af28>
    import seaborn as sns
    sns.set(style="ticks", palette="pastel")
    # Load the example tips dataset
    tips = sns.load_dataset("iris")
    # Draw a nested boxplot to show bills by day and time
    sns.boxplot(x="species", y="sepal_length", palette=["m", "g"],
    sns.despine(offset=10, trim=True)


    Or, you can create a heatmap.

    %matplotlib inline
    from string import ascii_letters
    import numpy as np
    import pandas as pd
    import seaborn as sns
    import matplotlib.pyplot as plt
    # Generate a large random dataset
    rs = np.random.RandomState(33)
    d = pd.DataFrame(data=rs.normal(size=(100, 26)),
    # Compute the correlation matrix
    corr = d.corr()
    # Generate a mask for the upper triangle
    mask = np.triu(np.ones_like(corr, dtype=np.bool))
    # Set up the matplotlib figure
    f, ax = plt.subplots(figsize=(11, 9))
    # Generate a custom diverging colormap
    cmap = sns.diverging_palette(220, 10, as_cmap=True)
    # Draw the heatmap with the mask and correct aspect ratio
    sns.heatmap(corr, mask=mask, cmap=cmap, vmax=.3, center=0,
                square=True, linewidths=.5, cbar_kws={"shrink": .5})
    <matplotlib.axes._subplots.AxesSubplot at 0x7f9167159a58>