Skip to content

Commit a18b341

Browse files
Merge branch 'master' into deep-magic-underscore-error-msg-rebase
2 parents 7d42ffe + d154171 commit a18b341

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+4142
-1045
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
plotly/_version.py export-subst
1+
packages/python/plotly/plotly/_version.py export-subst

.github/pull_request_template.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ below :-).
3333
- [ ] For a new feature, I have added documentation examples in an existing or
3434
new tutorial notebook (please see the doc checklist as well).
3535
- [ ] I have added a CHANGELOG entry if fixing/changing/adding anything substantial.
36+
- [ ] For a new feature or a change in behaviour, I have updated the relevant docstrings in the code to describe the feature or behaviour (please see the doc checklist as well).
3637
3738
-->

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ temp-plot.html
4646
doc/python/.ipynb_checkpoints
4747
doc/python/.mapbox_token
4848
doc/.ipynb_checkpoints
49+
tags
4950
doc/check-or-enforce-order.py

CHANGELOG.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,30 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5-
## [4.12.0] - unreleased
5+
## [4.13.0] - UNRELEASED
6+
7+
8+
9+
## [4.12.1] - UNRELEASED
10+
11+
12+
13+
## [4.12.0] - 2020-10-23
14+
15+
### Added
16+
17+
- For `add_trace`, `add_shape`, `add_annotation` and `add_layout_image`, the `row` and/or `col` argument now also accept the string `"all"`. `row="all"` adds the object to all the subplot rows and `col="all"` adds the object to all the subplot columns. ([#2840](https://github.com/plotly/plotly.py/pull/2840))
18+
- Shapes that reference the plot axes in one dimension and the data in another dimension can be added with the new `add_hline`, `add_vline`, `add_hrect`, `add_vrect` functions, which also support the `row="all"` and `col="all"` arguments. ([#2840](https://github.com/plotly/plotly.py/pull/2840))
19+
- The `add_trace`, `add_shape`, `add_annotation`, `add_layout_image`, `add_hline`, `add_vline`, `add_hrect`, `add_vrect` functions accept an argument `exclude_empty_subplots` which if `True`, only adds the object to subplots already containing traces or layout objects. This is useful in conjunction with the `row="all"` and `col="all"` arguments. ([#2840](https://github.com/plotly/plotly.py/pull/2840))
20+
- For all `go.Figure` functions accepting a selector argument (e.g., `select_traces`), this argument can now also be a function which is passed each relevant graph object (in the case of `select_traces`, it is passed every trace in the figure). For graph objects where this function returns true, the graph object is included in the selection. ([#2844](https://github.com/plotly/plotly.py/pull/2844))
621

722
### Added
823

924
- Better magic underscore error messages. For example, `some_fig.update_layout(geo_ltaxis_showgrid=True)` shows `Bad property path:\ngeo_ltaxis_showgrid\n ^` and lists the valid properties for `geo`.
1025

1126
### Updated
1227

13-
- Updated Plotly.js to version 1.57.0. See the [plotly.js CHANGELOG](https://github.com/plotly/plotly.js/blob/v1.57.0/CHANGELOG.md) for more information. These changes are reflected in the auto-generated `plotly.graph_objects` module.
28+
- Updated Plotly.js to version 1.57.1. See the [plotly.js CHANGELOG](https://github.com/plotly/plotly.js/blob/v1.57.1/CHANGELOG.md) for more information. These changes are reflected in the auto-generated `plotly.graph_objects` module.
1429

1530
## [4.11.0] - 2020-10-01
1631

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Our recommended IDE for Plotly’s Python graphing library is Dash Enterprise’
3737

3838
## Quickstart
3939

40-
`pip install plotly==4.11.0`
40+
`pip install plotly==4.12.0`
4141

4242
Inside [Jupyter notebook](https://jupyter.org/install) (installable with `pip install "notebook>=5.3" "ipywidgets>=7.2"`):
4343

@@ -86,13 +86,13 @@ Built on top of [plotly.js](https://github.com/plotly/plotly.js), `plotly.py` is
8686
plotly.py may be installed using pip...
8787

8888
```
89-
pip install plotly==4.11.0
89+
pip install plotly==4.12.0
9090
```
9191

9292
or conda.
9393

9494
```
95-
conda install -c plotly plotly=4.11.0
95+
conda install -c plotly plotly=4.12.0
9696
```
9797

9898
### Jupyter Notebook Support
@@ -129,10 +129,10 @@ Then run the following commands to install the required JupyterLab extensions (n
129129

130130
```
131131
# Basic JupyterLab renderer support
132-
jupyter labextension install jupyterlab-plotly@4.11.0
132+
jupyter labextension install jupyterlab-plotly@4.12.0
133133
134134
# OPTIONAL: Jupyter widgets extension for FigureWidget support
135-
jupyter labextension install @jupyter-widgets/jupyterlab-manager plotlywidget@4.11.0
135+
jupyter labextension install @jupyter-widgets/jupyterlab-manager plotlywidget@4.12.0
136136
```
137137

138138
Please check out our [Troubleshooting guide](https://plotly.com/python/troubleshooting/) if you run into any problems with JupyterLab.

binder/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
jupytext
2-
plotly==4.11.0
2+
plotly==4.12.0
33
jupyter
44
notebook
55
pandas==1.0.3

doc/apidoc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# The short X.Y version
2929
version = ""
3030
# The full version, including alpha/beta/rc tags
31-
release = "4.11.0"
31+
release = "4.12.0"
3232

3333

3434
# -- General configuration ---------------------------------------------------

doc/python/figure-structure.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,31 @@ The third of the three top-level attributes of a figure is `frames`, whose value
9595

9696
### The `config` Object
9797

98-
At [render-time](/python/renderers/), it is also possible to control certain figure behaviors which are not considered part of the figure proper i.e. the behaviour of the "modebar" and how the figure relates to mouse actions like scrolling etc. The object that contains these options is called the [`config`, and has its own documentation page](/python/configuration-options/). It is exposed in Python as the `config` keyword argument of the `.show()` method on `plotly.graph_objects.Figure` objects.
98+
At [render-time](/python/renderers/), it is also possible to control certain figure behaviors which are not considered part of the figure proper i.e. the behavior of the "modebar" and how the figure relates to mouse actions like scrolling etc. The object that contains these options is called the [`config`, and has its own documentation page](/python/configuration-options/). It is exposed in Python as the `config` keyword argument of the `.show()` method on `plotly.graph_objects.Figure` objects.
9999

100-
### Positioning With Paper or Container Coordinates
100+
### Positioning With Paper, Container Coordinates, or Axis Domain Coordinates
101101

102102
Various figure components configured within the layout of the figure support positioning attributes named `x` or `y`, whose values may be specified in "paper coordinates" (sometimes referred to as "plot fractions" or "normalized coordinates"). Examples include `layout.xaxis.domain` or `layout.legend.x` or `layout.annotation[].x`.
103103

104104
Positioning in paper coordinates is *not* done in absolute pixel terms, but rather in terms relative to a coordinate system defined with an origin `(0,0)` at `(layout.margin.l, layout.margin.b)` and a point `(1,1)` at `(layout.width-layout.margin.r, layout.height-layout.margin.t)` (note: `layout.margin` values are pixel values, as are `layout.width` and `layout.height`). Paper coordinate values less than 0 or greater than 1 are permitted, and refer to areas within the plot margins.
105105

106+
To position an object in "paper" coordinates, the corresponding axis reference
107+
is set to `"paper"`. For instance a shape's `xref` attribute would be set to
108+
`"paper"` so that the `x` value of the shape refers to its position in paper
109+
coordinates.
110+
106111
Note that the contents of the `layout.margin` attribute are by default computed based on the position and dimensions of certain items like the title or legend, and may be made dependent on the position and dimensions of tick labels as well when setting the `layout.xaxis.automargin` attribute to `True`. This has the effect of automatically increasing the margin values and therefore shrinking the physical area defined between the `(0,0)` and `(1,1)` points. Positioning certain items at paper coordinates less than 0 or greater than 1 will also trigger this behavior. The `layout.width` and `layout.height`, however, are taken as givens, so a figure will never grow or shrink based on its contents.
107112

108113
The figure title may be positioned using "container coordinates" which have `(0,0)` and `(1,1)` anchored at the bottom-left and top-right of the figure, respectively, and therefore are independent of the values of layout.margin.
109114

115+
Furthermore, shapes, annotations, and images can be placed relative to an axis's
116+
domain so that, for instance, an `x` value of `0.5` would place the object
117+
halfway along the x-axis, regardless of the domain as specified in the
118+
`layout.xaxis.domain` attribute. This behavior can be specified by adding
119+
`' domain'` to the axis reference in the axis referencing attribute of the object.
120+
For example, setting `yref = 'y2 domain'` for a shape will refer to the length
121+
and position of the axis named `y2`.
122+
110123
### 2D Cartesian Trace Types and Subplots
111124

112125
The most commonly-used kind of subplot is a [two-dimensional Cartesian subplot](/python/axes/). Traces compatible with these subplots support `xaxis` and `yaxis` attributes whose values must refer to corresponding objects in the layout portion of the figure. For example, if `xaxis="x"`, and `yaxis="y"` (which is the default) then this trace is drawn on the subplot at the intersection of the axes configured under `layout.xaxis` and `layout.yaxis`, but if `xaxis="x2"` and `yaxis="y3"` then the trace is drawn at the intersection of the axes configured under `layout.xaxis2` and `layout.yaxis3`. Note that attributes such as `layout.xaxis` and `layout.xaxis2` etc do not have to be explicitly defined, in which case default values will be inferred. Multiple traces of different types can be drawn on the same subplot.

doc/python/getting-started.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ We also encourage you to join the [Plotly Community Forum](http://community.plot
5959
`plotly` may be installed using pip...
6060

6161
```
62-
$ pip install plotly==4.11.0
62+
$ pip install plotly==4.12.0
6363
```
6464

6565
or conda.
6666

6767
```
68-
$ conda install -c plotly plotly=4.11.0
68+
$ conda install -c plotly plotly=4.12.0
6969
```
7070

7171
This package contains everything you need to write figures to standalone HTML files.
@@ -144,10 +144,10 @@ Then run the following commands to install the required JupyterLab extensions (n
144144

145145
```
146146
# JupyterLab renderer support
147-
jupyter labextension install jupyterlab-plotly@4.11.0
147+
jupyter labextension install jupyterlab-plotly@4.12.0
148148
149149
# OPTIONAL: Jupyter widgets extension
150-
jupyter labextension install @jupyter-widgets/jupyterlab-manager plotlywidget@4.11.0
150+
jupyter labextension install @jupyter-widgets/jupyterlab-manager plotlywidget@4.12.0
151151
```
152152

153153
These packages contain everything you need to run JupyterLab...
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
---
2+
jupyter:
3+
jupytext:
4+
notebook_metadata_filter: all
5+
text_representation:
6+
extension: .md
7+
format_name: markdown
8+
format_version: '1.2'
9+
jupytext_version: 1.3.0
10+
kernelspec:
11+
display_name: Python 3
12+
language: python
13+
name: python3
14+
language_info:
15+
codemirror_mode:
16+
name: ipython
17+
version: 3
18+
file_extension: .py
19+
mimetype: text/x-python
20+
name: python
21+
nbconvert_exporter: python
22+
pygments_lexer: ipython3
23+
version: 3.7.3
24+
plotly:
25+
description: How to add annotated horizontal and vertical lines in Python.
26+
display_as: file_settings
27+
language: python
28+
layout: base
29+
name: Shapes
30+
order: 37
31+
permalink: python/horizontal-vertical-shapes/
32+
thumbnail: thumbnail/horizontal-vertical-shapes.jpg
33+
---
34+
35+
### Horizontal and Vertical Lines and Boxes (Autoshapes) in Plotly.py
36+
37+
*introduced in plotly 4.12*
38+
39+
Horizontal and vertical lines and rectangles (autoshapes) that span an entire
40+
plot can be added via the `add_hline`, `add_vline`, `add_hrect`, and `add_vrect`
41+
methods of `plotly.graph_objects.Figure`. Shapes added with these methods are
42+
added as [layout shapes](/python/shapes) (as shown when doing `print(fig)`, for
43+
example). These shapes are fixed to the endpoints of one axis, regardless of the
44+
range of the plot, and fixed to data coordinates on the other axis. The
45+
following shows some possibilities, try panning and zooming the resulting figure
46+
to see how the shapes stick to some axes:
47+
48+
49+
```python
50+
import plotly.express as px
51+
52+
df = px.data.iris()
53+
fig = px.scatter(df, x="sepal_length", y="sepal_width")
54+
55+
# Add a vertical line that spans the entire y axis
56+
# intersecting the x axis at x=5
57+
fig.add_vline(x=5, line_color="red")
58+
# Add a horizontal line that spans the entire x axis
59+
# intersecting the y axis at y=3
60+
fig.add_hline(y=3, line_color="blue")
61+
# Add a vertical rectangle that spans the entire y axis
62+
# intersecting the x axis at 5.5 and 6.5
63+
fig.add_vrect(x0=5.5, x1=6.5, line_color="purple")
64+
# Add a horizontal rectangle that spans the entire x axis
65+
# intersecting the y axis at 2.5 and 4
66+
fig.add_hrect(y0=2.5, y1=4, line_color="orange")
67+
# (try panning and zooming the plot)
68+
fig.show()
69+
```
70+
71+
#### Adding Autoshapes to Multiple Facets / Subplots
72+
73+
The same line or box can be added to multiple facets by using the `'all'`
74+
keyword in the `row` and `col` arguments like with `Figure.add_shape`. For
75+
example
76+
```python
77+
import plotly.express as px
78+
79+
df = px.data.tips()
80+
fig = px.scatter(df, x="total_bill", y="tip", facet_row="smoker", facet_col="sex")
81+
# Adds a vertical line to all facets
82+
fig.add_vline(x=30, row="all", col="all", line_color="purple")
83+
# Adds a horizontal line to all the rows of the second column
84+
fig.add_hline(y=6, row="all", col=2, line_color="yellow")
85+
# Adds a vertical rectangle to all the columns of the first row
86+
fig.add_vrect(x0=20, x1=40, row=1, col="all", line_color="green")
87+
fig.show()
88+
```
89+
The default `row` and `col` values are `"all"` so
90+
`fig.add_vline(x=30, line_color="purple")` is equivalent
91+
to `fig.add_vline(x=30, row="all", col="all", line_color="purple")` in the above
92+
example.
93+
94+
#### Adding Text Annotations to Autoshapes
95+
96+
Text [annotations](/python/text-and-annotations) can be added to an autoshape
97+
using the `annotation` keyword. Using the above example:
98+
```python
99+
import plotly.express as px
100+
import plotly.graph_objects as go
101+
102+
df = px.data.tips()
103+
fig = px.scatter(df, x="total_bill", y="tip", facet_row="smoker", facet_col="sex")
104+
# Add annotations anchored to the top right corner of the resulting lines
105+
fig.add_vline(x=30, line_color="purple", annotation=go.layout.Annotation(text="A"))
106+
# Another way to add annotations when we are only interested in specifying text
107+
fig.add_hline(y=6, row="all", col=2, line_color="yellow", annotation_text="B")
108+
# Specify the position of the resulting annotations
109+
fig.add_vrect(
110+
x0=20,
111+
x1=40,
112+
row=1,
113+
col="all",
114+
line_color="green",
115+
annotation_text="C",
116+
annotation_position="bottom inside left",
117+
)
118+
fig.show()
119+
```
120+
Call `help` on any of the autoshape functions in the Python interpreter to learn
121+
more (e.g., `help(fig.add_vline)`).

0 commit comments

Comments
 (0)