Feature Request: Support list inputs for plotly express x, y arguments
See original GitHub issueFirst 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()
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (6 by maintainers)
Top GitHub Comments
We’ve actually gone ahead an implemented this feature after all! https://medium.com/plotly/beyond-tidy-plotly-express-now-accepts-wide-form-and-mixed-form-data-bdc3e054f891
@eisenlohr as of 4.8.2,
line_group="variable"
by default forpx.line
😃