-
Notifications
You must be signed in to change notification settings - Fork 15
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
docs: Add unsafe_update_figure
doc
#1058
Open
jnumainville
wants to merge
4
commits into
deephaven:main
Choose a base branch
from
jnumainville:docs_push_unsafe_update_figure
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+862
−0
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# `unsafe_update_figure` Chart Customization | ||
|
||
To customize a chart in a way that is not directly supported by Deephaven Plotly Express (`dx`), use the `unsafe_update_figure` parameter. | ||
A Plotly `Figure` object backs every `dx` chart, and `unsafe_update_figure` allows you to directly modify this object. | ||
|
||
> [!WARNING] | ||
> `dx` maps `Table` columns to an index of a trace within `Figure.data` which will break if the trace order changes. Do not remove traces. Add new traces at the end of the list. | ||
|
||
`unsafe_update_figure` accepts a function that takes a Plotly `Figure` object as input and optionally returns a modified `Figure` object. If a figure is not returned, it is assumed that the input figure has been modified in place. | ||
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. Should link to full plotly.js docs where they can see figure docs 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. done, linked on the first instance |
||
|
||
## Examples | ||
|
||
### Bar Line | ||
|
||
Add a line to bars in a bar plot with `update_traces`. | ||
|
||
```python | ||
import deephaven.plot.express as dx | ||
|
||
tips = dx.data.tips() | ||
|
||
|
||
def update(figure): | ||
# Add a gray line to the bars | ||
figure.update_traces(marker_line_width=3, marker_line_color="gray") | ||
|
||
|
||
bar_lined_plot = dx.bar(tips, x="Day", unsafe_update_figure=update) | ||
``` | ||
|
||
### Legend Location | ||
|
||
Change the location of the legend to the bottom of the plot by updating the layout. | ||
|
||
```python | ||
import deephaven.plot.express as dx | ||
|
||
tips = dx.data.tips() | ||
|
||
|
||
def update(figure): | ||
# Update the layout to move the legend to the bottom | ||
# y is negative to move the legend outside the plot area | ||
figure.update_layout( | ||
legend=dict(orientation="h", yanchor="bottom", y=-0.3, xanchor="left", x=0.3) | ||
) | ||
|
||
|
||
legend_bottom_plot = dx.scatter( | ||
tips, x="TotalBill", y="Tip", color="Day", unsafe_update_figure=update | ||
) | ||
``` | ||
|
||
### Vertical Line | ||
|
||
Add a vertical line to a plot with `add_vline`. | ||
|
||
```python | ||
import deephaven.plot.express as dx | ||
|
||
tips = dx.data.tips() | ||
|
||
|
||
def update(figure): | ||
# Add a dashed orange vertical line at x=20 | ||
figure.add_vline(x=20, line_width=3, line_dash="dash", line_color="orange") | ||
|
||
|
||
scatter_vline_plot = dx.scatter( | ||
tips, x="TotalBill", y="Tip", unsafe_update_figure=update | ||
) | ||
``` | ||
|
||
### Between Line Fill | ||
|
||
Fill the area between lines in a line plot with `fill="tonexty"`. | ||
|
||
```python | ||
import deephaven.plot.express as dx | ||
|
||
my_table = dx.data.stocks() | ||
|
||
# subset data for just DOG transactions and add upper and lower bounds | ||
dog_prices = my_table.where("Sym = `DOG`").update_view( | ||
["UpperPrice = Price + 5", "LowerPrice = Price - 5"] | ||
) | ||
|
||
|
||
def update(figure): | ||
# tonexty fills the area between the trace and the previous trace in the list | ||
figure.update_traces( | ||
fill="tonexty", fillcolor="rgba(123,67,0,0.3)", selector={"name": "LowerPrice"} | ||
) | ||
figure.update_traces( | ||
fill="tonexty", fillcolor="rgba(123,67,0,0.3)", selector={"name": "Price"} | ||
) | ||
|
||
|
||
# Order matters for y since the fill is between the trace and the previous trace in the list | ||
filled_line_plot = dx.line( | ||
dog_prices, | ||
x="Timestamp", | ||
y=["UpperPrice", "Price", "LowerPrice"], | ||
unsafe_update_figure=update, | ||
) | ||
``` |
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.
I would directly state why it is labelled "unsafe" at the start of this warning.
Update figure is marked "unsafe" because some modifications can entirely break your figure, and care must be taken to not ...
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.
done