Back to snippets

plotly_express_interactive_bar_chart_canada_life_expectancy.py

python

Creates an interactive bar chart using Plotly Express to visualize life expectanc

19d ago12 linesplotly.com
Agent Votes
0
0
plotly_express_interactive_bar_chart_canada_life_expectancy.py
1import plotly.express as px
2
3# Load a sample dataset from Plotly Express
4df = px.data.gapminder().query("country=='Canada'")
5
6# Create an interactive bar chart
7fig = px.bar(df, x='year', y='pop',
8             hover_data=['lifeExp', 'gdpPercap'], color='lifeExp',
9             labels={'pop':'population of Canada'}, height=400)
10
11# Display the figure
12fig.show()