-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Documentation updates for 5.11 #3931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2cec00e
Update legend.md
LiamConnors 2576230
add example of bounds
LiamConnors d94d667
Merge branch 'master' into docs-oct
LiamConnors d739f6d
basic cluster example
LiamConnors 93cd690
Update mapbox-layers.md
LiamConnors 09fc158
Update scattermapbox.md
LiamConnors 30bf41b
Update scattermapbox.md
LiamConnors c234bb1
Update mapbox-layers.md
LiamConnors 8940b93
Update legend.md
LiamConnors 2249203
Update mapbox-layers.md
LiamConnors d7aa9e5
Update legend.md
LiamConnors 94196a6
Update legend.md
LiamConnors bd896ee
Update setting-graph-size.md
LiamConnors fded25c
add marker updates
LiamConnors 2d3714b
Update marker-style.md
LiamConnors e909b32
Create dumbbell-plots.md
LiamConnors 79c49c1
standoff example
LiamConnors File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,176 @@ | ||
--- | ||
jupyter: | ||
jupytext: | ||
notebook_metadata_filter: all | ||
text_representation: | ||
extension: .md | ||
format_name: markdown | ||
format_version: '1.3' | ||
jupytext_version: 1.14.1 | ||
kernelspec: | ||
display_name: Python 3 (ipykernel) | ||
language: python | ||
name: python3 | ||
language_info: | ||
codemirror_mode: | ||
name: ipython | ||
version: 3 | ||
file_extension: .py | ||
mimetype: text/x-python | ||
name: python | ||
nbconvert_exporter: python | ||
pygments_lexer: ipython3 | ||
version: 3.8.0 | ||
plotly: | ||
description: How to create dumbbell plots in Python with Plotly. | ||
display_as: basic | ||
language: python | ||
layout: base | ||
name: Dumbbell Plots | ||
order: 19 | ||
page_type: example_index | ||
permalink: python/dumbbell-plots/ | ||
thumbnail: thumbnail/dumbbell-plot.jpg | ||
--- | ||
|
||
## Basic Dumbbell Plot | ||
|
||
|
||
Dumbbell plots are useful for demonstrating change between two sets of data points, for example, the population change for a selection of countries for two different years | ||
|
||
In this example, we compare life expectancy in 1952 with life expectancy in 2002 for countries in Europe. | ||
|
||
```python | ||
import plotly.graph_objects as go | ||
from plotly import data | ||
|
||
import pandas as pd | ||
|
||
df = data.gapminder() | ||
df = df.loc[(df.continent == "Europe") & (df.year.isin([1952, 2002]))] | ||
|
||
countries = ( | ||
df.loc[(df.continent == "Europe") & (df.year.isin([2002]))] | ||
.sort_values(by=["lifeExp"], ascending=True)["country"] | ||
.unique() | ||
) | ||
|
||
data = {"x": [], "y": [], "colors": [], "years": []} | ||
|
||
for country in countries: | ||
data["x"].extend( | ||
[ | ||
df.loc[(df.year == 1952) & (df.country == country)]["lifeExp"].values[0], | ||
df.loc[(df.year == 2002) & (df.country == country)]["lifeExp"].values[0], | ||
None, | ||
] | ||
) | ||
data["y"].extend([country, country, None]), | ||
data["colors"].extend(["green", "blue", "brown"]), | ||
data["years"].extend(["1952", "2002", None]) | ||
|
||
fig = go.Figure( | ||
data=[ | ||
go.Scatter( | ||
x=data["x"], | ||
y=data["y"], | ||
mode="lines", | ||
marker=dict( | ||
color="grey", | ||
), | ||
), | ||
go.Scatter( | ||
x=data["x"], | ||
y=data["y"], | ||
mode="markers+text", | ||
marker=dict( | ||
color=data["colors"], | ||
size=10, | ||
), | ||
hovertemplate="""Country: %{y} <br> Life Expectancy: %{x} <br><extra></extra>""", | ||
), | ||
] | ||
) | ||
|
||
fig.update_layout( | ||
title="Life Expectancy in Europe: 1952 and 2002", | ||
width=1000, | ||
height=1000, | ||
showlegend=False, | ||
) | ||
|
||
fig.show() | ||
|
||
``` | ||
|
||
## Dumbbell Plot with Arrow Markers | ||
|
||
*Note: The `arrow`, `angleref`, and `standoff` properties used on the `marker` in this example are new in 5.11* | ||
|
||
In this example, we add arrow markers to the plot. The first trace adds the lines connecting the data points and arrow markers. | ||
The second trace adds circle markers. On the first trace, we use `standoff=8` to position the arrow marker back from the data point. | ||
For the arrow marker to point directly at the circle marker, this value should be half the circle marker size. | ||
|
||
```python | ||
import pandas as pd | ||
import plotly.graph_objects as go | ||
from plotly import data | ||
|
||
df = data.gapminder() | ||
df = df.loc[(df.continent == "Europe") & (df.year.isin([1952, 2002]))] | ||
|
||
countries = ( | ||
df.loc[(df.continent == "Europe") & (df.year.isin([2002]))] | ||
.sort_values(by=["lifeExp"], ascending=True)["country"] | ||
.unique() | ||
) | ||
|
||
data = {"x": [], "y": [], "colors": [], "years": []} | ||
|
||
for country in countries: | ||
data["x"].extend( | ||
[ | ||
df.loc[(df.year == 1952) & (df.country == country)]["lifeExp"].values[0], | ||
df.loc[(df.year == 2002) & (df.country == country)]["lifeExp"].values[0], | ||
None, | ||
] | ||
) | ||
data["y"].extend([country, country, None]), | ||
data["colors"].extend(["silver", "lightskyblue", "white"]), | ||
data["years"].extend(["1952", "2002", None]) | ||
|
||
fig = go.Figure( | ||
data=[ | ||
go.Scatter( | ||
x=data["x"], | ||
y=data["y"], | ||
mode="markers+lines", | ||
marker=dict( | ||
symbol="arrow", color="black", size=16, angleref="previous", standoff=8 | ||
), | ||
), | ||
go.Scatter( | ||
x=data["x"], | ||
y=data["y"], | ||
text=data["years"], | ||
mode="markers", | ||
marker=dict( | ||
color=data["colors"], | ||
size=16, | ||
), | ||
hovertemplate="""Country: %{y} <br> Life Expectancy: %{x} <br> Year: %{text} <br><extra></extra>""", | ||
), | ||
] | ||
) | ||
|
||
fig.update_layout( | ||
title="Life Expectancy in Europe: 1952 and 2002", | ||
width=1000, | ||
height=1000, | ||
showlegend=False, | ||
) | ||
|
||
|
||
fig.show() | ||
|
||
``` |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a cool page, thanks for adding it!
Some feedback:
This is not blocking feedback, just something that's on my mind as I've always wanted a PX function to do this stuff :)