Search⌘ K
AI Features

Exercise: Continuous vs. Categorical Bivariate Analysis

Explore continuous and categorical bivariate analysis techniques using Plotly. Learn to create bar charts, box plots with multiple traces, and ECDF curves to visualize relationships in your data effectively.

Exercise 1

Create a bar chart in Plotly graph objects that detail the revenue per math (in thousands of Euros) for each of the top 10 leagues. We’ll use the sport_organisation_figures.csv dataset.

Python 3.5
# Prerequisite
sports = pd.read_csv('/usr/local/csvfiles/sport_organisation_figures.csv')
top_leagues = sports.iloc[:11, :].copy()

Solution

  • The below code snippet creates a bar chart using the go.Bar() function on line 2 from the plotly.graph_objs module.

  • The x-axis represents the League column of the top_leagues DataFrame, and the y-axis represents the Revenue per match (in thousands of euros) column.

  • A new figure object is created using the go.Figure() function on line 6 with the trace as its data. Finally, the show() function is called to display the generated bar chart.

Python 3.5
# Create trace
trace = go.Bar(x=top_leagues['League'],
y=top_leagues['Revenue per match (in thousands of euros)'])
# Add trace to figure and show
fig = go.Figure(data=[trace])
fig.show()

Exercise 2

Using Plotly graph ...