question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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()

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
nicolaskruchtencommented, May 26, 2020
0reactions
nicolaskruchtencommented, Jun 27, 2020

@eisenlohr as of 4.8.2, line_group="variable" by default for px.line 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plotly express arguments in Python
Over 14 examples of Plotly Express Arguments including changing color, size, log axes, and more in Python.
Read more >
plotly.express package — 5.11.0 documentation
This parameter is used to force a specific ordering of values per column. The keys of this dict should correspond to column names,...
Read more >
Visualization with Plotly.Express: Comprehensive guide
A detailed guide on how to create many visualizations with Plotly Express with layout styling, interactivity, animations, and many chart ...
Read more >
Python Plotly tutorial - GeeksforGeeks
Plotly supports various types of plots like line charts, scatter plots, histograms, cox plots, etc. So you all must be wondering why Plotly...
Read more >
Chapter 4. Visualization with Matplotlib - O'Reilly
We can see that this scatter plot has given us the ability to simultaneously explore four different dimensions of the data: the (x,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found