Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/main/08. Data Visualization with Python/08. Plotly Basics.ipynb
Views: 4585
Basic Plotly Charts
Objectives
In this lab, you will learn about creating plotly charts using plotly.graph_objects and plotly.express.
Learn more about:
Handling data using Pandas
We will be using the airline dataset from Data Asset eXchange.
Airline Reporting Carrier On-Time Performance Dataset
The Reporting Carrier On-Time Performance Dataset contains information on approximately 200 million domestic US flights reported to the United States Bureau of Transportation Statistics. The dataset contains basic information about each flight (such as date, time, departure airport, arrival airport) and, if applicable, the amount of time the flight was delayed and information about the reason for the delay. This dataset can be used to predict the likelihood of a flight arriving on time.
Preview data, dataset metadata, and data glossary here.
Read Data
Lab structure
plotly.graph_objects
Review scatter plot creation
Theme: How departure time changes with respect to airport distance
To do - Create line plot
Theme: Extract average monthly delay time and see how it changes over the year
plotly.express
Review bar chart creation
Theme: Extract number of flights from a specific airline that goes to a destination
To do - Create bubble chart
Theme: Get number of flights as per reporting airline
To do - Create histogram
Theme: Get distribution of arrival delay
Review pie chart
Theme: Proportion of distance group by month (month indicated by numbers)
To do - Create sunburst chart
Theme: Hierarchical view in othe order of month and destination state holding value of number of flights
plotly.graph_objects¶
1. Scatter Plot
Learn more about usage of scatter plot here
Idea: How departure time changes with respect to airport distance
2. Line Plot
Learn more about line plot here
Idea: Extract average monthly arrival delay time and see how it changes over the year.
To do:
Create a line plot with x-axis being the month and y-axis being computed average delay time. Update plot title, xaxis, and yaxis title.
Hint: Scatter and line plot vary by updating mode parameter.
plotly.express¶
1. Bar Chart
Learn more about bar chart here
Idea: Extract number of flights from a specific airline that goes to a destination
2. Bubble Chart
Learn more about bubble chart here
Idea: Get number of flights as per reporting airline
To do
Create a bubble chart using the
bub_data
with x-axis being reporting airline and y-axis being flights.Provide title to the chart
Update size of the bubble based on the number of flights. Use
size
parameter.Update name of the hover tooltip to
reporting_airline
usinghover_name
parameter.
Double-click here for the solution.
Histogram
Learn more about histogram here
Idea: Get distribution of arrival delay
To do
Use px.histogram and pass the dataset.
Pass
ArrDelay
to x parameter.
Double-click here for the solution.
Pie Chart
Learn more about pie chart here
Idea: Proportion of distance group by month (month indicated by numbers)
Sunburst Charts
Learn more about sunburst chart here
Idea: Hierarchical view in othe order of month and destination state holding value of number of flights
To do
Create sunburst chart using
px.sunburst
.Define hierarchy of sectors from root to leaves in
path
parameter. Here, we go fromMonth
toDestStateName
feature.Set sector values in
values
paramter. Here, we can pass inFlights
feature.Show the figure.