Skip to content

Feature Request: Support list inputs for plotly express x, y arguments #2224

Closed
@samjett247

Description

@samjett247

First off, thanks for the awesome plotly.express package, its fulfilling a great need for interactive plotting capabilities.

One problem I've encountered frequently is that I have variables I want to plot in separate columns in my dataframe, and I have to make a subplot to plot the distributions or correlations of all of these variables. For these purposes, it would be very helpful if px.scatter, px.box , and the other px methods could accept the lists of column names as x or y variables. Note that this is different from faceting by column or row, because for the facet: (a) the yaxes and/or xaxes are typically shared, and (b) the "column" or row to be faceted on is a single column. Would love to hear the communities thoughts about this idea. Example code below.

import plotly.express as px
from plotly.subplots import make_subplots
import pandas as pd

temp = [
    {"Clinic": "A", "Subject": "Bill", "Height(cm)": 182, "Weight(kg)": 101, "BloodPressureHigh": 128, "BloodPressureLow": 90},
    {"Clinic": "A", "Subject": "Susie", "Height(cm)": 142, "Weight(kg)": 67, "BloodPressureHigh": 120, "BloodPressureLow": 70},
    {"Clinic": "B", "Subject": "John", "Height(cm)": 202, "Weight(kg)": 89, "BloodPressureHigh": 118, "BloodPressureLow": 85},
    {"Clinic": "B", "Subject": "Stacy", "Height(cm)": 156, "Weight(kg)": 78, "BloodPressureHigh": 114, "BloodPressureLow": 76},
    {"Clinic": "B", "Subject": "Lisa", "Height(cm)": 164, "Weight(kg)": 59, "BloodPressureHigh": 112, "BloodPressureLow": 74} 
]
df = pd.DataFrame(temp)
# This is the call I want to be able to make
# px.box(data_frame=df, x='Clinic', y=['Height(cm)', 'Weight(kg)', "BloodPressureHigh", "BloodPressureLow"]) 

# Instead, this is what I have to do
fig = make_subplots(rows=1, cols=4)
for j,y in enumerate(['Height(cm)', 'Weight(kg)', "BloodPressureHigh", "BloodPressureLow"]):
    localfig = px.box(data_frame=df, x='Clinic', y=y) 
    # Or the below if you want to plot scatter
    # localfig = px.scatter(data_frame=df, x='Height(cm)', y=y)
    trace1 = localfig['data'][0]
    fig.add_trace(trace1, row=1, col=j+1)
fig.show()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions