plotly / plotly_express

Plotly Express - Simple syntax for complex charts. Now integrated into plotly.py!
https://plot.ly/python/plotly-express/
MIT License
4 stars 0 forks source link

Plotting with a for loop #144

Closed robroc closed 5 years ago

robroc commented 5 years ago

I'm trying to produce multiple line plots, one for each column in my data, by looping over the columns. Nothing gets displayed in Jupyter Lab. Is this possible to do?

Python 3.6 Jupyter Lab 1.0.2 plotly==4.0.0 plotly-express==0.4.0

Code sample:


for stat in stats:
    px.line(data, x = 'sequence', y = stat, color = 'category', height= 200, title = stat)
nicolaskruchten commented 5 years ago

Short answer: add .show() to the end of the call.

Long answer: px.<whatever>() functions return a Figure object. If this function call happens to be the final call in a Jupyter cell, then the figure will display itself, otherwise it's "just another object". To force the figure to display itself, call .show() on it.

Longer answer: there's a long doc page about this here https://plot.ly/python/renderers/

happy plotting!

nicolaskruchten commented 5 years ago

PS I strongly recommend upgrading to plotly version 4.1.1 as there's a nasty bug in 4.0.0

robroc commented 5 years ago

Worked like a charm. Thanks for the quick help!