Create Bubblechart
Tags: #plotly #chart #bubblechart #dataviz #snippet #operations #image #html
Last update: 2023-04-12 (Created: 2022-03-07)
Description: This notebook provides instructions on how to create a bubble chart using Plotly.
import naas
import plotly.express as px
import pandas as pd
title = "Life Expectancy vs GDP per Capita GDP, 2007"
# Output paths
output_image = f"{title}.png"
output_html = f"{title}.html"
df = px.data.gapminder()
df
fig = px.scatter(
df.query("year==2007"),
x="gdpPercap",
y="lifeExp",
size="pop",
color="continent",
hover_name="country",
log_x=True,
size_max=60,
)
fig.update_layout(
plot_bgcolor="#ffffff",
margin=dict(l=0, r=0, t=50, b=50),
width=1200,
height=800,
showlegend=False,
xaxis_nticks=36,
title=title,
xaxis=dict(
title="GDP per capita (dollars)",
gridcolor="white",
type="log",
gridwidth=2,
),
yaxis=dict(
title="Life Expectancy (years)",
gridcolor="white",
gridwidth=2,
),
)
config = {"displayModeBar": False}
fig.show(config=config)
fig.write_image(output_image, width=1200)
fig.write_html(output_html)
link_image = naas.asset.add(output_image)
link_html = naas.asset.add(output_html, {"inline": True})
# -> Uncomment the line below to remove your assets
# naas.asset.delete(output_image)
# naas.asset.delete(output_html)
Last modified 1mo ago