Introduction to Data Visualization with Plotly in Python
Alex Scriven
Data Scientist
Plotly has a number of unique advantages:
plotly.express
Plotly graphs can be created:
plotly.express
for quick plots (px
)plotly.graph_objects
(go
) for more customization$$
📈 We will spend most of our time on px
Save the links to key documentation!
Detailed reference page for specific plots
$$
For Scatter plots:
plotly.express
page with examplesA basic plotly figure:
import plotly.express as px
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] temperatures = [28, 27, 25, 31, 32, 35, 36]
fig = px.bar( x=days, y=temperatures, title="Temperatures of the week")
fig.show()
Plotly Figure components:
layout
: Dictionary controlling style of the figurelayout
per figuredata
: List of dictionaries setting graph type and data itselftrace
. There are over 40 types!frames
: For animated plots (beyond this course)
print(fig)
Figure({'data': [{'type': 'bar',
'x': array(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'
, 'Saturday','Sunday'], dtype=object),
'y': {'bdata': 'HBsZHyAjJA==....'}],
'layout': {'title': {'text': 'Temperatures of the week'}}})
$$
Introduction to Data Visualization with Plotly in Python