-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Demo] Add lollipop chart to ViViVo (#874)
Co-authored-by: Petar Pejovic <[email protected]>
- Loading branch information
1 parent
ed15ddc
commit 2b656bf
Showing
9 changed files
with
199 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
vizro-core/examples/visual-vocabulary/pages/examples/lollipop.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import pandas as pd | ||
import plotly.express as px | ||
import plotly.graph_objects as go | ||
from vizro.models.types import capture | ||
|
||
|
||
@capture("graph") | ||
def lollipop(data_frame: pd.DataFrame, **kwargs): | ||
"""Creates a lollipop chart using Plotly.""" | ||
fig = px.scatter(data_frame, **kwargs) | ||
|
||
orientation = fig.data[0].orientation | ||
x_or_y = "x" if orientation == "h" else "y" | ||
y_or_x = "y" if orientation == "h" else "x" | ||
|
||
for x_or_y_value, y_or_x_value in zip(fig.data[0][x_or_y], fig.data[0][y_or_x]): | ||
fig.add_trace(go.Scatter({x_or_y: [0, x_or_y_value], y_or_x: [y_or_x_value, y_or_x_value], "mode": "lines"})) | ||
|
||
fig.update_traces( | ||
marker_size=12, | ||
line_width=3, | ||
line_color=fig.layout.template.layout.colorway[0], | ||
) | ||
|
||
fig.update_layout( | ||
{ | ||
"showlegend": False, | ||
f"{x_or_y}axis_showgrid": True, | ||
f"{y_or_x}axis_showgrid": False, | ||
f"{x_or_y}axis_rangemode": "tozero", | ||
}, | ||
) | ||
return fig | ||
|
||
|
||
gapminder = ( | ||
px.data.gapminder() | ||
.query("year == 2007 and country.isin(['United States', 'Pakistan', 'India', 'China', 'Indonesia'])") | ||
.sort_values("pop") | ||
) | ||
|
||
fig = lollipop(gapminder, y="country", x="pop") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters