Recipe: How to generate scatter plot using Pandas and Seaborn?
DATA VISUALIZATION PANDAS CHEATSHEET

How to generate scatter plot using Pandas and Seaborn?

This recipe helps you generate scatter plot using Pandas and Seaborn
In [2]:
## How to generate scatter plot using Pandas and Seaborn
def Snippet_116():
    print()
    print(format('How to scatter plot using Pandas and Seaborn','*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # load libraries
    import pandas as pd
    import random
    import matplotlib.pyplot as plt
    import seaborn as sns

    # Create empty dataframe
    df = pd.DataFrame()

    # Add columns
    df['x'] = random.sample(range(1, 1000), 75)
    df['y'] = random.sample(range(1, 1000), 75)

    # View first few rows of data
    print(); print(df.head())

    # Set style of scatterplot
    sns.set_context("notebook", font_scale=1.1)
    sns.set_style("ticks")

    # Create scatterplot of dataframe without regression line
    sns.lmplot('x', 'y', data=df, fit_reg=False, # Don't fit a regression line
               scatter_kws={"marker": "D", "s": 100}) # S marker size

    # Set title & labels
    plt.title('Scatter Plot of Data without Regression Line')
    plt.xlabel('X Axis')
    plt.ylabel('Y Axis')
    plt.show()

    # Create scatterplot of dataframe with regression line
    sns.lmplot('x', 'y', data=df, fit_reg=True, # Don't fit a regression line
               scatter_kws={"marker": "D", "s": 100}) # S marker size

    # Set title & labels
    plt.title('Scatter Plot of Data with Regression Line')
    plt.xlabel('X Axis')
    plt.ylabel('Y Axis')
    plt.show()

Snippet_116()
*******************How to scatter plot using Pandas and Seaborn*******************

     x    y
0   85  510
1  220  820
2  285  495
3  354  409
4  442  647


Stuck at work?
Can't find the recipe you are looking for. Let us know and we will find an expert to create the recipe for you. Click here
Companies using this Recipe
1 developer from Vodafone
1 developer from ANAC
1 developer from HvH
1 developer from ICU Medical