Data Visualisation — How to Plot a Scatter Bubble Chart by Plotly

Figure 1 A Scatter Bubble Chart of Life Expectancy versus GDP per capita (in log scale). Source of Data: Our World in Data
  1. Install plotly and import plotly.express in Google Colab
! pip install plotly==5.0.0
import plotly.express as px
import pandas as pd
from google.colab import drive
drive.mount('/content/drive/')
data = pd.read_csv("drive/MyDrive/Colab Notebooks/life-expectancy-vs-gdp-per-capita.csv")
data.head(5)
#define df2015 as the data of Year=2015df2015 = data.query("Year==2015")#plot the scatter plot by px of df2015 with x, y axis definedfig2015 = px.scatter(df2015, x="GDP per capita", y="Life expectancy")
fig2015.show()
Figure 2 A scatterplot of life expectancy versus GDP per capita.
df2015 = data.query("Year==2015")#just add log_x=True to convert x-axis to log scalefig2015 = px.scatter(df2015, x="GDP per capita", y="Life expectancy", log_x=True)
fig2015.show()
Figure 3 A scatterplot of life expectancy versus GDP per capita in log scale — a stronger linear relationship is shown.
df2015 = data.query("Year==2015")
fig2015 = px.scatter(df2015, x="GDP per capita", y="Life expectancy", log_x=True, size="Total population", size_max=60, color="Continent", hover_name="Country")
fig2015.show()
Figure 4 A scatter bubble chart of life expectancy versus GDP per capita in log scale — a stronger linear relationship is shown and the clusters of countries in different continents and their population sizes can easily be compared.
Figure 5 Plotly Python Open Source graphing library basic charts. source https://plotly.com/python/basic-charts/
Figure 6 The Scatter Bubble Chart provided by Our World in Data webpage. https://ourworldindata.org/grapher/life-expectancy-vs-gdp-per-capita

--

--

--

ecyY — easy to understand why, easy to study why. Finding the truths scientifically is the theme.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Visualizing and Representation of Stocks

Comparing Graph Databases

Weekly picks by Ali Alohali — مختارات اسبوعيه بواسطة علي العوهلي — Issue #28

Build Quick Models with Dabl

If the sum of all 10 values in the data set are 10, then what will be the average: (CSS MPT 2022)

Bayesian Inference: Beyond Estimating Statistical Models

How to Create Interactive Plots with Altair

Data Analytics — Coding in Colab

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
ecyY

ecyY

ecyY — easy to understand why, easy to study why. Finding the truths scientifically is the theme.

More from Medium

Collecting Historical Weather Data

Beautiful plots with Seaborn

Plotting time series plot with matplotlib

Building Pie Chart, Stacked Bar Chart & Column Bar Chart (With Data Labels) Using Matplotlib &…