Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

5/10/23, 18:21 about:blank

Data Visualization with Python


Cheat Sheet : Plotly and Dash
Function Description Syntax Example
Plotly Express
Create a scatter px.scatter(dataframe, x=x_column,
scatter px.scatter(df, x=age_array, y=income_array)
plot y=y_column)
Create a line px.line( x=x_column,
line px.line(x=months_array, y=no_bicycle_sold_array)
plot y=y_column,'title')
Create a bar px.bar( x=x_column, px.bar( x=grade_array, y=score_array,
bar
plot y=y_column,title='title') title='Pass Percentage')
px.sunburst(dataframe, path= px.sunburst(data, path=['Month',
Create a
sunburst [col1,col2..], 'DestStateName'], values='Flights',title='Flight
sunbust plot values='column',title='title') Distribution Hierarchy')
Create a px.histogram(x=heights_array,title="Distribution
histogram px.histogram(x=x,title="title")
histogram of Heights")
px.scatter(bub_data, x="City",
Create a px.scatter(dataframe, y="Numberofcrimes",
bubble
bubble chart x=x,y=y,size=size,title="title") size="Numberofcrimes",hover_name="City",
title='Crime Statistics')
px.pie(values=exp_percent,
Create a pie
pie px.pie(values=x,names=y,title="title") names=house_holdcategories, title='Household
chart Expenditure')
Plotly Graph Objects
go.Scatter(x=age_array, y=income_array,
Scatter Create a scatter go.Scatter(x=x, y=y, mode='markers') mode='markers')
Create a line go.Bar(x=months_array,
go.Scatter(x=x, y=y, mode='lines')
plot y=no_bicycle_sold_array,mode='lines')
Add additional
fig.add_trace(go.Scatter(x=months_array,
add_trace traces to an fig.add_trace(trace_object)
y=no_bicycle_sold_array))
existing figure
Update the
layout of a
figure, such as fig.update_layout(title='Bicycle Sales',
update_layout fig.update_layout(layout_object) xaxis_title='Months', yaxis_title='Number of
title, axis Bicycles Sold')
labels, and
annotations.
Dash
Create an input
dash_core_components.Input dcc.Input(value='', type='text') dcc.Input(value='Hello', type='text')
component
Create a graph
dash_core_components.Graph dcc.Graph(figure=fig) dcc.Graph(figure=fig)
component
Create a div html.Div(children=[html.H1('Hello Dash'),
dash_html_components.Div html.Div(children=component_list)
element html.P('Welcome to Dash')])
Create a dcc.Dropdown(options=[{'label': 'Option 1',
dcc.Dropdown(options=options_list,
dash_core_components.Dropdown dropdown value=default_value)
'value': '1'}, {'label': 'Option 2', 'value':
component '2'}], value='1')

Author(s)
Dr. Pooja

Changelog
Date Version Changed by Change Description
2023-06-19 0.1 Dr. Pooja Initial version created

about:blank 1/1

You might also like