ScaterPlot With Scrub Filter

Set Up

Before Starting make sure to have Observable-Jupyter and any other needed libraries installed in your local environment.

[10]:
from observable_jupyter import embed
import pandas as pd
import json
from palmerpenguins import load_penguins

Load and Format Data

[11]:
penguins_data = load_penguins()
penguins_data.head()
[11]:
species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g sex year
0 Adelie Torgersen 39.1 18.7 181.0 3750.0 male 2007
1 Adelie Torgersen 39.5 17.4 186.0 3800.0 female 2007
2 Adelie Torgersen 40.3 18.0 195.0 3250.0 female 2007
3 Adelie Torgersen NaN NaN NaN NaN NaN 2007
4 Adelie Torgersen 36.7 19.3 193.0 3450.0 female 2007

The following block of code structures the data into a format accepted by Observable.

[12]:
result = penguins_data.to_json(orient="records")
parsed = json.loads(result)
data = json.dumps(parsed, indent=4)
Formated_Data = json.loads(data)

Embed your data into the visualization

The ScaterPlot With Scrub Filter visualization consists of three cells:

  1. vegaPetalsWidget : Desplays the graph

  2. viewof sepalLengthLimits : Desplays the top scrub filter

  3. viewof sepalWidthLimits : Desplays the bottom scrub filter

To make your visualization work you will need to access the input variables:

  1. input_data : set equal to your structured data.

  2. x_title : set to the title of the column containg the data you want on the x axis.

  3. y_title : set to the title of the column containg the data you want on the y axis.

  4. legend : set to the name of the column in your data that allows you to difrerentiate your data.

  5. specified_feature_1 : Set to a value you want to filter by.

  6. specified_feature_2 : Set to a value you want to filter by.

[13]:
embed(
    '@rstorni/visualize-a-data-frame-with-observable-in-jupyter/2',
    cells=['vegaPetalsWidget', 'viewof sepalLengthLimits', 'viewof sepalWidthLimits'],
    inputs = {
        'input_data' : Formated_Data,
        'x_title' : "bill_length_mm",
        'y_title' : "bill_depth_mm",
        'legend' : 'species',
        'specified_feature_1': "body_mass_g",
        'specified_feature_2': "flipper_length_mm"
    }
)

Images/Thumbnails/Scrub_Filter_ScaterPlot.png