22 lines
920 B
Python
22 lines
920 B
Python
"""
|
|
Display sales of various cities in a sunburst chart.
|
|
|
|
Given the cities can have recurring parents, we can have
|
|
a sunburst chart with 2 rings, the centermost ring for the
|
|
country, and the outmost ring to have sales per city.
|
|
"""
|
|
import pandas as pd
|
|
import plotly
|
|
from plotly.express import sunburst
|
|
|
|
if __name__ == '__main__':
|
|
df = pd.DataFrame(data={
|
|
"country": ["France", "France", "Spain", "Spain", "England", "England", "England"],
|
|
"city": ["Montpellier", "Bordeaux", "Madrid", "Valencia", "London", "Manchester", "Bristol"],
|
|
"sales": [150_000, 127_000, 97_200, 137_250, 200_000, 180_000, 150_000]
|
|
})
|
|
plot = sunburst(df, path=["country", "city"], values="sales", title="Sales by country and city", template="ggplot2",
|
|
color_discrete_sequence=plotly.colors.qualitative.Dark2)
|
|
plot.layout.update({"font": {"family": "Cabin", "size": 13}})
|
|
plot.show()
|