Add source example files
This commit is contained in:
21
source/plotting/charts/plotly_sunburst.py
Normal file
21
source/plotting/charts/plotly_sunburst.py
Normal file
@ -0,0 +1,21 @@
|
||||
"""
|
||||
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()
|
Reference in New Issue
Block a user