-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Documentation for 5.10 features #3818
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 21 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
a8ae4ab
Update parallel-coordinates-plot.md
LiamConnors 7f97ac2
Adding a prefix and suffix
LiamConnors 7ff8954
Create selections.md
LiamConnors cfcf5f5
Update link
LiamConnors 16880be
add methods to calculate quartiles
LiamConnors 540d9d9
Update violin.md
LiamConnors 600bf7a
Update setting-graph-size.md
LiamConnors 11347f2
minor edits
LiamConnors 15afc11
Update indicator.md
LiamConnors b47c824
Update indicator.md
LiamConnors e8d9959
minor edits
LiamConnors 8741c88
Update setting-graph-size.md
LiamConnors 5627314
Update doc/python/selections.md
LiamConnors ae737ac
Update doc/python/selections.md
LiamConnors b5fa284
Update parallel-coordinates-plot.md
LiamConnors c5bf5df
Update parallel-coordinates-plot.md
LiamConnors 3682408
Update selections.md
LiamConnors e955334
Update selections.md
LiamConnors 186dec4
Update doc/python/selections.md
LiamConnors 6d1a2da
Update selections.md
LiamConnors e2eb238
add time series example
LiamConnors cb07e20
Update selections.md
LiamConnors 0e536e9
Update selections.md
LiamConnors fbc1668
Update selections.md
LiamConnors a8c5649
Update doc/python/selections.md
LiamConnors 263a9b8
add random seed
LiamConnors 9e66af4
Update doc/python/selections.md
LiamConnors 222b3b2
Update selections.md
LiamConnors b705619
Update doc/python/selections.md
LiamConnors 1d753ed
Update selections.md
LiamConnors fa2f3f4
Update selections.md
LiamConnors c674802
Update selections.md
LiamConnors 51e599e
Update selections.md
LiamConnors 66443e1
Merge branch 'master' into docs-5-10
LiamConnors 9417bcb
Update doc/python/selections.md
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
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
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,155 @@ | ||
--- | ||
jupyter: | ||
jupytext: | ||
notebook_metadata_filter: all | ||
text_representation: | ||
extension: .md | ||
format_name: markdown | ||
format_version: '1.3' | ||
jupytext_version: 1.13.7 | ||
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.9.0 | ||
plotly: | ||
description: How to use selections in Python. Examples of adding and styling selections. | ||
display_as: file_settings | ||
language: python | ||
layout: base | ||
name: Selections | ||
order: 26 | ||
LiamConnors marked this conversation as resolved.
Show resolved
Hide resolved
|
||
permalink: python/selections/ | ||
thumbnail: thumbnail/make_selection.jpg | ||
--- | ||
|
||
## Adding Selections | ||
LiamConnors marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
*New in 5.10* | ||
|
||
You can add persistent selections to a rendered figure using the **Box Select** and **Lasso Select** tools in the mode bar. | ||
To add multiple selections, select **Shift** when making new selections. | ||
To clear a selection, double-click it. On a subplot you can clear all selections by double-clicking any unselected area of the subplot. | ||
|
||
|
||
|
||
You can also add selections to a figure that displays when it renders using `fig.add_selection`. | ||
Here, we add a rectangular selection with a region between `3.0` and `6.5` on the x axis and between `3.5` and `5.5` on the y axis. | ||
|
||
|
||
```python | ||
import plotly.express as px | ||
|
||
df = px.data.iris() | ||
|
||
fig = px.scatter(df, x="sepal_width", y="sepal_length") | ||
fig.add_selection(x0=3.0, y0=6.5, x1=3.5, y1=5.5) | ||
|
||
fig.show() | ||
``` | ||
|
||
## Selections Using a Custom SVG | ||
|
||
|
||
In the above example, we added a rectangular selection. You can also render a custom SVG for a selection by defining a `path` that can include single or multiple polygons. Here, we create a selection with a single polygon path "M2,6.5L4,7.5L4,6Z". | ||
|
||
Please note that multiple polygons e.g. "M0,0L0,10L10,10,L10,0Z M2,2L2,8L8,8,L8,2Z" could be used to subtract certain regions from the selection. | ||
|
||
```python | ||
import plotly.express as px | ||
|
||
df = px.data.iris() | ||
|
||
fig = px.scatter(df, x="sepal_width", y="sepal_length") | ||
fig.add_selection(path="M2,6.5L4,7.5L4,6Z") | ||
|
||
fig.show() | ||
``` | ||
archmoj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
archmoj marked this conversation as resolved.
Show resolved
Hide resolved
archmoj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
## Styling Selections | ||
|
||
|
||
In the above example, we added a selection to the figure that is displayed when the figure renders. | ||
`fig.add_selection` accepts additional properties that you can use to style the selection. Here, we add a `color`, `width`, and specify the `dash` type for the selection. | ||
|
||
|
||
```python | ||
import plotly.express as px | ||
|
||
df = px.data.iris() | ||
|
||
fig = px.scatter(df, x="sepal_width", y="sepal_length") | ||
fig.add_selection( | ||
x0=2.5, y0=6.5, x1=3.5, y1=5.5, | ||
line=dict( | ||
color="Crimson", | ||
width=2, | ||
dash="dash", | ||
)) | ||
|
||
fig.show() | ||
|
||
``` | ||
|
||
## Fill Color for Active Selections | ||
|
||
You can style the active selection with `activeselection`. In this example, we set active selections (when created or clicked) to appear with a `fillcolor` of `yellow`. | ||
|
||
```python | ||
import plotly.express as px | ||
|
||
df = px.data.iris() | ||
|
||
fig = px.scatter(df, x="sepal_width", y="sepal_length") | ||
fig.add_selection(x0=3.0, y0=6.5, x1=3.5, y1=5.5) | ||
|
||
fig.update_layout(dragmode='select', | ||
activeselection=dict(fillcolor='yellow')) | ||
|
||
fig.show() | ||
``` | ||
|
||
## Styling New Selections | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move this section above |
||
|
||
You can style new selections made on the figure by setting properties on `newselection`. | ||
Try making a new selection on the figure to try it out. | ||
|
||
```python | ||
import plotly.express as px | ||
|
||
df = px.data.iris() | ||
|
||
fig = px.scatter(df, x="sepal_width", y="sepal_length") | ||
|
||
fig.update_layout(dragmode='select', | ||
newselection=dict(line=dict(color='blue'))) | ||
|
||
fig.show() | ||
``` | ||
|
||
## Selections with Time Series | ||
|
||
Selections are also supported on time series figures. Here, we add a rectangular selection with a region between the dates `2019-01-01"` and `"2019-10-01"` on the x axis and between `1` and `1.15` on the y axis. | ||
|
||
|
||
```python | ||
import plotly.express as px | ||
|
||
df = px.data.stocks() | ||
fig = px.line(df, x='date', y="GOOG") | ||
fig.add_selection(x0="2019-01-01", y0=1, x1="2019-10-01", y1=1.17) | ||
archmoj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fig.show() | ||
``` | ||
|
||
archmoj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
## More on Selections | ||
|
||
For more on selections, see the [selections section of the `dcc.Graph` page](https://dash.plotly.com/dash-core-components/graph#selections) in the Dash docs. |
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.
Uh oh!
There was an error while loading. Please reload this page.