Skip to content

Commit d8b337e

Browse files
merging master
2 parents e8027f0 + e882f85 commit d8b337e

File tree

858 files changed

+1165
-74
lines changed

Some content is hidden

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

858 files changed

+1165
-74
lines changed

.circleci/create_conda_optional_env.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if [ ! -d $HOME/miniconda/envs/circle_optional ]; then
1616
# Create environment
1717
# PYTHON_VERSION=2.7 or 3.5
1818
$HOME/miniconda/bin/conda create -n circle_optional --yes python=$PYTHON_VERSION \
19-
requests nbformat six retrying psutil pandas decorator pytest mock nose poppler xarray scikit-image ipython jupyter ipykernel ipywidgets
19+
requests nbformat six retrying psutil pandas decorator pytest mock nose poppler xarray scikit-image ipython jupyter ipykernel ipywidgets statsmodels
2020

2121
# Install orca into environment
2222
$HOME/miniconda/bin/conda install --yes -n circle_optional -c plotly plotly-orca==1.3.1

.github/pull_request_template.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ below :-).
3232
modified existing tests.
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).
35+
- [ ] I have added a CHANGELOG entry if fixing/changing/adding anything substantial.
3536
3637
-->

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
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+
## Dev version
6+
7+
### Added
8+
9+
- The `hover_data` parameter of `px` functions can now be a dictionary. This
10+
makes it possible to skip hover information for some arguments or to change
11+
the formatting of hover informatiom [#2377](https://github.com/plotly/plotly.py/pull/2377).
12+
13+
### Performance
14+
This version includes several performance improvements ([#2368](https://github.com/plotly/plotly.py/pull/2368), [#2403](https://github.com/plotly/plotly.py/pull/2403)).
15+
16+
- Child graph objects (e.g. `figure.layout.xaxis`) are no longer created eagerly during graph object construction. Instead, they are created lazily the first time the property is accessed.
17+
- Property validation is now disabled for select internal operations.
18+
- When used with Python 3.7 and above, ploty.py now takes advantage of [PEP-562](https://www.python.org/dev/peps/pep-0562/) to perform submodule imports lazily. This dramatically improves import times.
19+
520
## [4.6] - 2020-03-31
621

722
### Updated

doc/python/hover-text-and-formatting.md

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fig.show()
123123

124124
### Customizing Hover text with Plotly Express
125125

126-
Plotly Express functions automatically add all the data being plotted (x, y, color etc) to the hover label. Many Plotly Express functions also support configurable hover text. The `hover_data` argument accepts a list of column names to be added to the hover tooltip. The `hover_name` property controls which column is displayed in bold as the tooltip title.
126+
Plotly Express functions automatically add all the data being plotted (x, y, color etc) to the hover label. Many Plotly Express functions also support configurable hover text. The `hover_data` argument accepts a list of column names to be added to the hover tooltip, or a dictionary for advanced formatting (see the next section). The `hover_name` property controls which column is displayed in bold as the tooltip title.
127127

128128
Here is an example that creates a scatter plot using Plotly Express with custom hover data and a custom hover name.
129129

@@ -138,15 +138,42 @@ fig = px.scatter(df_2007, x="gdpPercap", y="lifeExp", log_x=True,
138138
fig.show()
139139
```
140140

141+
### Disabling or customizing hover of columns in plotly express
142+
143+
`hover_data` can also be a dictionary. Its keys are existing columns of the `dataframe` argument, or new labels. For an existing column, the values can be
144+
* `False` to remove the column from the hover data (for example, if one wishes to remove the column of the `x` argument)
145+
* `True` to add a different column, with default formatting
146+
* a formatting string starting with `:` for numbers [d3-format's syntax](https://github.com/d3/d3-3.x-api-reference/blob/master/Formatting.md#d3_forma), and `|` for dates in [d3-time-format's syntax](https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Formatting.md#format), for example `:.3f`, `|%a`.
147+
148+
It is also possible to pass new data as values of the `hover_data` dict, either as list-like data, or inside a tuple, which first element is one of the possible values described above for existing columns, and the second element correspond to the list-like data, for example `(True, [1, 2, 3])` or `(':.1f', [1.54, 2.345])`.
149+
150+
These different cases are illustrated in the following example.
151+
152+
```python
153+
import plotly.express as px
154+
import numpy as np
155+
df = px.data.iris()
156+
fig = px.scatter(df, x='petal_length', y='sepal_length', facet_col='species', color='species',
157+
hover_data={'species':False, # remove species from hover data
158+
'sepal_length':':.2f', # customize hover for column of y attribute
159+
'petal_width':True, # add other column, default formatting
160+
'sepal_width':':.2f', # add other column, customized formatting
161+
# data not in dataframe, default formatting
162+
'suppl_1': np.random.random(len(df)),
163+
# data not in dataframe, customized formatting
164+
'suppl_2': (':.3f', np.random.random(len(df)))
165+
})
166+
fig.update_layout(height=300)
167+
fig.show()
168+
```
169+
141170
### Customizing hover text with a hovertemplate
142171

143-
To customize the tooltip on your graph you can use [hovertemplate](https://plotly.com/python/reference/#pie-hovertemplate), which is a template string used for rendering the information that appear on hoverbox.
172+
To customize the tooltip on your graph you can use the [hovertemplate](https://plotly.com/python/reference/#pie-hovertemplate) attribute of `graph_objects` tracces, which is a template string used for rendering the information that appear on hoverbox.
144173
This template string can include `variables` in %{variable} format, `numbers` in [d3-format's syntax](https://github.com/d3/d3-3.x-api-reference/blob/master/Formatting.md#d3_forma), and `date` in [d3-time-format's syntax](https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Formatting.md#format).
145174
Hovertemplate customize the tooltip text vs. [texttemplate](https://plotly.com/python/reference/#pie-texttemplate) which customizes the text that appears on your chart. <br>
146175
Set the horizontal alignment of the text within tooltip with [hoverlabel.align](https://plotly.com/python/reference/#layout-hoverlabel-align).
147176

148-
Plotly Express automatically sets the `hovertemplate`, but you can set it manually when using `graph_objects`.
149-
150177
```python
151178
import plotly.graph_objects as go
152179

@@ -187,6 +214,24 @@ fig = go.Figure(go.Pie(
187214
fig.show()
188215
```
189216

217+
### Modifying the hovertemplate of a plotly express figure
218+
219+
`plotly.express` automatically sets the hovertemplate but you can modify it using the `update_traces` method of the generated figure. It helps to print the hovertemplate generated by `plotly.express` in order to be able to modify it. One can also revert to the default hover information of traces by setting the hovertemplate to `None`.
220+
221+
```python
222+
import plotly.express as px
223+
224+
df_2007 = px.data.gapminder().query("year==2007")
225+
226+
fig = px.scatter(df_2007, x="gdpPercap", y="lifeExp", log_x=True, color='continent'
227+
)
228+
print("plotly express hovertemplate:", fig.data[0].hovertemplate)
229+
fig.update_traces(hovertemplate='GDP: %{x} <br>Life Expectany: %{y}') #
230+
fig.update_traces(hovertemplate=None, selector={'name':'Europe'}) # revert to default hover
231+
print("user_defined hovertemplate:", fig.data[0].hovertemplate)
232+
fig.show()
233+
```
234+
190235
### Advanced Hover Template
191236

192237
The following example shows how to format hover template. [Here](https://plotly.com/python/v3/hover-text-and-formatting/#dash-example) is an example to see how to format hovertemplate in Dash.

doc/python/imshow.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.2'
9-
jupytext_version: 1.3.1
9+
jupytext_version: 1.4.2
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.6.8
23+
version: 3.7.7
2424
plotly:
2525
description: How to display image data in Python with Plotly.
2626
display_as: scientific

packages/python/plotly/_plotly_utils/basevalidators.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,12 +2438,12 @@ def description(self):
24382438

24392439
return desc
24402440

2441-
def validate_coerce(self, v, skip_invalid=False):
2441+
def validate_coerce(self, v, skip_invalid=False, _validate=True):
24422442
if v is None:
24432443
v = self.data_class()
24442444

24452445
elif isinstance(v, dict):
2446-
v = self.data_class(v, skip_invalid=skip_invalid)
2446+
v = self.data_class(v, skip_invalid=skip_invalid, _validate=_validate)
24472447

24482448
elif isinstance(v, self.data_class):
24492449
# Copy object
@@ -2614,7 +2614,7 @@ def get_trace_class(self, trace_name):
26142614

26152615
return self._class_map[trace_name]
26162616

2617-
def validate_coerce(self, v, skip_invalid=False):
2617+
def validate_coerce(self, v, skip_invalid=False, _validate=True):
26182618
from plotly.basedatatypes import BaseTraceType
26192619

26202620
# Import Histogram2dcontour, this is the deprecated name of the
@@ -2649,15 +2649,15 @@ def validate_coerce(self, v, skip_invalid=False):
26492649
if skip_invalid:
26502650
# Treat as scatter trace
26512651
trace = self.get_trace_class("scatter")(
2652-
skip_invalid=skip_invalid, **v_copy
2652+
skip_invalid=skip_invalid, _validate=_validate, **v_copy
26532653
)
26542654
res.append(trace)
26552655
else:
26562656
res.append(None)
26572657
invalid_els.append(v_el)
26582658
else:
26592659
trace = self.get_trace_class(trace_type)(
2660-
skip_invalid=skip_invalid, **v_copy
2660+
skip_invalid=skip_invalid, _validate=_validate, **v_copy
26612661
)
26622662
res.append(trace)
26632663
else:

packages/python/plotly/codegen/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ def perform_codegen():
266266
for dep_clas in DEPRECATED_DATATYPES:
267267
root_datatype_imports.append(f"._deprecations.{dep_clas}")
268268

269-
validate_import = "from .._validate import validate\n"
270269
optional_figure_widget_import = f"""
271270
if sys.version_info < (3, 7):
272271
try:
@@ -307,7 +306,7 @@ def __getattr__(import_name):
307306
rel_classes = datatype_rel_class_imports[path_parts]
308307
rel_modules = datatype_rel_module_imports.get(path_parts, [])
309308
if path_parts == ():
310-
init_extra = validate_import + optional_figure_widget_import
309+
init_extra = optional_figure_widget_import
311310
else:
312311
init_extra = ""
313312
write_init_py(graph_objs_pkg, path_parts, rel_modules, rel_classes, init_extra)
@@ -325,7 +324,7 @@ def __getattr__(import_name):
325324
graph_objects_init_source = build_from_imports_py(
326325
graph_objects_rel_modules,
327326
graph_objects_rel_classes,
328-
init_extra=validate_import + optional_figure_widget_import,
327+
init_extra=optional_figure_widget_import,
329328
)
330329
graph_objects_path = opath.join(outdir, "graph_objects", "__init__.py")
331330
os.makedirs(opath.join(outdir, "graph_objects"), exist_ok=True)

packages/python/plotly/codegen/datatypes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ def __init__(self"""
349349
# Handle skip_invalid
350350
# -------------------
351351
self._skip_invalid = kwargs.pop('skip_invalid', False)
352+
self._validate = kwargs.pop('_validate', True)
352353
"""
353354
)
354355

packages/python/plotly/plotly/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
".io",
7373
".data",
7474
".colors",
75-
".express",
7675
],
7776
[".version.__version__"],
7877
)

packages/python/plotly/plotly/_validate.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)