-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
add_{hline,vline,hrect,vrect}
and add_{shape,image,annotation}
to multiple facets, squashed
#2840
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
Changes from 3 commits
ad54177
a7d95be
6a86381
be7eb0f
0c5126c
00eca47
9cc5777
e2f18b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,116 @@ | ||||||
--- | ||||||
jupyter: | ||||||
jupytext: | ||||||
notebook_metadata_filter: all | ||||||
text_representation: | ||||||
extension: .md | ||||||
format_name: markdown | ||||||
format_version: '1.2' | ||||||
jupytext_version: 1.3.0 | ||||||
kernelspec: | ||||||
display_name: Python 3 | ||||||
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.7.3 | ||||||
plotly: | ||||||
description: How to add annotated horizontal and vertical lines in Python. | ||||||
display_as: file_settings | ||||||
language: python | ||||||
layout: base | ||||||
name: Shapes | ||||||
order: 37 | ||||||
permalink: python/horizontal-vertical-shapes/ | ||||||
thumbnail: thumbnail/horizontal-vertical-shapes.jpg | ||||||
--- | ||||||
|
||||||
### Horizontal and Vertical Lines and Boxes (Autoshapes) in Plotly.py | ||||||
|
||||||
Horizontal and vertical lines and rectangles (autoshapes) that span an entire | ||||||
plot can be added via the `add_hline`, `add_vline`, `add_hrect`, and `add_vrect` | ||||||
methods of `plotly.graph_objects.Figure`. These shapes are fixed to the | ||||||
endpoints of one axis, regardless of the range of the plot, and fixed to data | ||||||
coordinates on the other axis. For example | ||||||
|
coordinates on the other axis. For example | |
coordinates on the other axis. Shapes added with these methods are added as [layout shapes](/python/shapes) (as shown when doing `print(fig)`, for example). For example |
Outdated
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.
could you please add a link to the annotations tutorial?
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.
Good idea, sure! Is this how you do it? [annotations](/python/text-and-annotations)
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 think we discourage using go
objects like this inside functions, so you could write dict(text="A")
instead (@nicolaskruchten can you please confirm?)
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.
yeah let's use a dict here please.
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.
Wait, this was one of the specifications, that it should accept a go.layout.Annotation
object, as well as a dict, this is to show that fact.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -309,15 +309,15 @@ fig.show(config={'doubleClick': 'reset'}) | |
|
||
_introduced in plotly 4.7_ | ||
|
||
It can be useful to add shapes to a layout image, for highlighting an object, drawing bounding boxes as part of a machine learning training set, or identifying seeds for a segmentation algorithm. | ||
It can be useful to add shapes to a layout image, for highlighting an object, drawing bounding boxes as part of a machine learning training set, or identifying seeds for a segmentation algorithm. | ||
|
||
In order to enable shape drawing, you need to | ||
- define a dragmode corresponding to a drawing tool (`'drawline'`,`'drawopenpath'`, `'drawclosedpath'`, `'drawcircle'`, or `'drawrect'`) | ||
- add [modebar buttons](/python/configuration-options#add-optional-shapedrawing-buttons-to-modebar) corresponding to the drawing tools you wish to use. | ||
|
||
The style of new shapes is specified by the `newshape` layout attribute. Shapes can be selected and modified after they have been drawn. More details and examples are given in the [tutorial on shapes](/python/shapes#drawing-shapes-on-cartesian-plots). | ||
|
||
Drawing or modifying a shape triggers a `relayout` event, which [can be captured by a callback inside a Dash application](https://dash.plotly.com/interactive-graphing). | ||
Drawing or modifying a shape triggers a `relayout` event, which [can be captured by a callback inside a Dash application](https://dash.plotly.com/interactive-graphing). | ||
|
||
```python | ||
import plotly.graph_objects as go | ||
|
@@ -339,7 +339,7 @@ fig.add_layout_image( | |
) | ||
fig.update_xaxes(showgrid=False, range=(0, img_width)) | ||
fig.update_yaxes(showgrid=False, scaleanchor='x', range=(img_height, 0)) | ||
# Line shape added programatically | ||
# Line shape added programatically | ||
fig.add_shape( | ||
type='line', xref='x', yref='y', | ||
x0=650, x1=1080, y0=380, y1=180, line_color='cyan' | ||
|
@@ -359,5 +359,8 @@ fig.show(config={'modeBarButtonsToAdd':['drawline', | |
]}) | ||
``` | ||
|
||
|
||
### Images Placed Relative to the Axes | ||
|
||
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. placeholder for example here? 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. Yes, woops ;) |
||
#### Reference | ||
See https://plotly.com/python/reference/layout/images/ for more information and chart attribute options! | ||
See https://plotly.com/python/reference/layout/images/ for more information and chart attribute options! |
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.
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.
maybe also mention that users can pan and zoom, the shapes will adapt