본문 바로가기

Data Science/Visualization

[plotly] Plotly Express in Python

1. What is Plotly Express?

The plotly.express module contains functions that can create entire figures at once, and is reffered to as Plotly Express or PX. Plotly Express is a built-in part of the plotly library, and is the recommended starting point for creating most common figures. Every Plotly Express function uses graph objects internally and returns a plotly.graph_objects.Figure instance.

 

2. What is Figure objects?

The plotly Python package exists to create, manipulate and render graphical figures represented by data structures also referred to as figures. Figures can be represented in Python either as dicts or as instances of the plotly.graph_objects.Figure class, and are serialized as text in JSON before being passed to Plotly.js.

 

Figure({
    'data': [{'hovertemplate': 'x=%{x}<br>y=%{y}<extra></extra>',
              'legendgroup': '',
              'line': {'color': '#636efa', 'dash': 'solid'},
              'marker': {'symbol': 'circle'},
              'mode': 'lines',
              'name': '',
              'orientation': 'v',
              'showlegend': False,
              'type': 'scatter',
              'x': array(['a', 'b', 'c'], dtype=object),
              'xaxis': 'x',
              'y': array([1, 3, 2]),
              'yaxis': 'y'}],
    'layout': {'legend': {'tracegroupgap': 0},
               'template': '...',
               'title': {'text': 'sample figure'},
               'xaxis': {'anchor': 'y', 'domain': [0.0, 1.0], 'title': {'text': 'x'}},
               'yaxis': {'anchor': 'x', 'domain': [0.0, 1.0], 'title': {'text': 'y'}}}
})

 

3. How to use Plotly Express?

Step 1 : Import plotly express library

import plotly.express as px

 

Step 2 : Declare Figure object of plotly express

import plotly.express as px 
df = px.data.iris() 
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species")

 

Step 3 : Show chart with Figure.show() method

import plotly.express as px 
df = px.data.iris() 
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
fig.show()

'Data Science > Visualization' 카테고리의 다른 글

[plotly] Layout components of plotly  (0) 2022.09.18
[plotly] Graph Objects in Python  (0) 2022.09.18
[plotly] iplot in Python  (0) 2022.09.18
[plotly] Getting Started with Plotly in Python  (0) 2022.09.18