Skip to content

Commit 09dc038

Browse files
authored
Merge pull request #5627 from plotly/remove-deprecated-ff
Remove deprecated Figure Factory functions
2 parents 50bb20b + c8ea5ff commit 09dc038

40 files changed

Lines changed: 79 additions & 12992 deletions

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## Unreleased
66

7+
### Removed
8+
- Remove the deprecated Figure Factory functions `create_2d_density`, `create_annotated_heatmap`, `create_bullet`, `create_candlestick`, `create_choropleth`, `create_distplot`, `create_facet_grid`, `create_gantt`, `create_hexbin_mapbox`, `create_ohlc`, `create_scatterplotmatrix`, and `create_violin` [[#5627](https://github.com/plotly/plotly.py/pull/5627)]
9+
710
### Fixed
811
- Raise a clear `ValueError` when an unsupported marginal plot type is passed to Plotly Express, instead of failing later with a cryptic `'NoneType' object has no attribute 'constructor'` message [[#5625](https://github.com/plotly/plotly.py/pull/5625)], with thanks to @eugen-goebel for the contribution!
912

README.md

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,6 @@ or conda
125125
conda install -c conda-forge python-kaleido
126126
```
127127

128-
### Extended Geo Support
129-
130-
Some plotly.py features rely on fairly large geographic shape files. The county
131-
choropleth figure factory is one such example. These shape files are distributed as a
132-
separate `plotly-geo` package. This package can be installed using pip...
133-
134-
```
135-
pip install plotly-geo==1.0.0
136-
```
137-
138-
or conda
139-
140-
```
141-
conda install -c plotly plotly-geo=1.0.0
142-
```
143-
144-
`plotly-geo` can be found on Github at https://github.com/plotly/plotly-geo.
145-
146128
## Copyright and Licenses
147129

148130
Code and documentation copyright 2019 Plotly, Inc.

doc/apidoc/plotly.figure_factory.rst

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,11 @@
99
:toctree: generated/
1010
:template: function.rst
1111

12-
create_2d_density
13-
create_annotated_heatmap
14-
create_bullet
15-
create_candlestick
16-
create_choropleth
1712
create_dendrogram
18-
create_distplot
19-
create_facet_grid
20-
create_gantt
2113
create_hexbin_map
22-
create_ohlc
2314
create_quiver
24-
create_scatterplotmatrix
2515
create_streamline
2616
create_table
2717
create_ternary_contour
2818
create_trisurf
29-
create_violin
3019

doc/python/annotated-heatmap.md

Lines changed: 13 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ jupyter:
3838

3939
*New in v5.5*
4040

41-
As of version 5.5.0 of `plotly`, the **recommended way to [display annotated heatmaps is to use `px.imshow()`](/python/heatmaps/)** rather than the now-deprecated `create_annotated_heatmap` figure factory documented below for historical reasons.
41+
Plotly Express provides the [`px.imshow()`](/python/heatmaps/) function which can be used for creating annotated heatmaps.
4242

4343

4444
#### Basic Annotated Heatmap for z-annotations
4545

4646
*New in v5.5*
4747

48-
After creating a figure with `px.imshow`, you can add z-annotations with `.update_traces(texttemplate="%{z}")`.
48+
When creating a figure with `px.imshow`, you can pass the parameter `text_auto=True` to add z-annotations.
4949

5050
```python
5151
import plotly.express as px
@@ -60,50 +60,9 @@ fig = px.imshow(z, text_auto=True)
6060
fig.show()
6161
```
6262

63-
### Deprecated Figure Factory
63+
#### Custom Text and Axis Labels
6464

65-
The remaining examples show how to create Annotated Heatmaps with the deprecated `create_annotated_heatmap` [figure factory](/python/figure-factories/).
66-
67-
68-
#### Simple Annotated Heatmap
69-
70-
```python
71-
import plotly.figure_factory as ff
72-
73-
z = [[.1, .3, .5, .7, .9],
74-
[1, .8, .6, .4, .2],
75-
[.2, 0, .5, .7, .9],
76-
[.9, .8, .4, .2, 0],
77-
[.3, .4, .5, .7, 1]]
78-
79-
fig = ff.create_annotated_heatmap(z)
80-
fig.show()
81-
```
82-
83-
#### Custom Text and X & Y Labels
84-
set `annotation_text` to a matrix with the same dimensions as `z`
85-
86-
> WARNING: this legacy figure factory requires the `y` array to be provided in reverse order, and will map the `z_text` to the `z` values in reverse order. **The use of the `px.imshow()` version below is highly recommended**
87-
88-
```python
89-
import plotly.figure_factory as ff
90-
91-
z = [[.1, .3, .5],
92-
[1.0, .8, .6],
93-
[.6, .4, .2]]
94-
95-
x = ['Team A', 'Team B', 'Team C']
96-
y = ['Game Three', 'Game Two', 'Game One']
97-
98-
z_text = [['Win', 'Lose', 'Win'],
99-
['Lose', 'Lose', 'Win'],
100-
['Win', 'Win', 'Lose']]
101-
102-
fig = ff.create_annotated_heatmap(z, x=x, y=y, annotation_text=z_text, colorscale='Viridis')
103-
fig.show()
104-
```
105-
106-
Here is the same figure using `px.imshow()`
65+
To annotate cells with text other than the `z` values, set the `text` attribute with `update_traces` and display it with a `texttemplate`. You can also label the axes by passing `x` and `y`.
10766

10867
```python
10968
import plotly.express as px
@@ -125,27 +84,9 @@ fig.update_xaxes(side="top")
12584
fig.show()
12685
```
12786

128-
#### Annotated Heatmap with numpy
129-
130-
```python
131-
import plotly.figure_factory as ff
132-
import numpy as np
133-
np.random.seed(1)
134-
135-
z = np.random.randn(20, 20)
136-
z_text = np.around(z, decimals=2) # Only show rounded value (full value on hover)
137-
138-
fig = ff.create_annotated_heatmap(z, annotation_text=z_text, colorscale='Greys',
139-
hoverinfo='z')
140-
141-
# Make text size smaller
142-
for i in range(len(fig.layout.annotations)):
143-
fig.layout.annotations[i].font.size = 8
144-
145-
fig.show()
146-
```
87+
#### Annotated Heatmap with a NumPy Array
14788

148-
Here is the same figure using `px.imshow()`
89+
`px.imshow` works directly with NumPy arrays. Pass a [`d3-format`](https://github.com/d3/d3-format/tree/v1.4.5#d3-format) string to `text_auto` to control how the annotations are formatted.
14990

15091
```python
15192
import plotly.express as px
@@ -158,10 +99,14 @@ fig = px.imshow(z, text_auto=".2f", color_continuous_scale='Greys', aspect="auto
15899
fig.show()
159100
```
160101

161-
Here is a fairly contrived example showing how one can display a periodic table with custom text and hover using `ff.create_annotated_heatmap()` (scroll below to see the `px.imshow()` equivalent).
102+
#### Periodic Table with Custom Text and Hover
103+
104+
`px.imshow()` can produce more elaborate annotated heatmaps. The example below renders a periodic table: the cell labels come from a custom `text` array, while `customdata` combined with a `hovertemplate` displays the element name and atomic mass on hover.
162105

163106
```python
164-
# Periodic Table Data
107+
import plotly.express as px
108+
import numpy as np
109+
165110
symbol = [['H', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'He'],
166111
['Li', 'Be', '', '', '', '', '', '', '', '', '', '', 'B', 'C', 'N', 'O', 'F', 'Ne'],
167112
['Na', 'Mg', '', '', '', '', '', '', '', '', '', '', 'Al', 'Si', 'P', 'S', 'Cl', 'Ar'],
@@ -214,36 +159,10 @@ color = [[.8, .0, .0, .0, .0, .0, .0, .0, .0, .0, .0, .0, .0, .0, .0, .0, .0, 1.
214159
[.1, .1, .1, .3, .3, .3, .5, .5, .5, .7, .7, .7, .9, .9, .9, .0, .0, .0],
215160
[.2, .2, .2, .4, .4, .4, .6, .6, .6, .8, .8, .8, 1., 1., 1., .0, .0, .0]]
216161

217-
# Set Colorscale
218162
colorscale=[[0.0, 'rgb(255,255,255)'], [.2, 'rgb(255, 255, 153)'],
219163
[.4, 'rgb(153, 255, 204)'], [.6, 'rgb(179, 217, 255)'],
220164
[.8, 'rgb(240, 179, 255)'],[1.0, 'rgb(255, 77, 148)']]
221165

222-
# Display element name and atomic mass on hover
223-
hover=[]
224-
for x in range(len(symbol)):
225-
hover.append([i + '<br>' + 'Atomic Mass: ' + str(j) if i else ''
226-
for i, j in zip(element[x], atomic_mass[x])])
227-
228-
import plotly.figure_factory as ff
229-
# Make Annotated Heatmap
230-
fig = ff.create_annotated_heatmap(color[::-1], annotation_text=symbol[::-1], text=hover[::-1],
231-
colorscale=colorscale, font_colors=['black'], hoverinfo='text')
232-
fig.update_layout(
233-
title_text='Periodic Table',
234-
margin=dict(l=10, r=10, t=10, b=10, pad=10),
235-
xaxis=dict(zeroline=False, showgrid=False),
236-
yaxis=dict(zeroline=False, showgrid=False, scaleanchor="x"),
237-
)
238-
fig.show()
239-
```
240-
241-
Here is the same output using `px.imshow()` with much less array manipulation:
242-
243-
```python
244-
import plotly.express as px
245-
import numpy as np
246-
247166
fig = px.imshow(color, color_continuous_scale=colorscale, aspect="auto",
248167
title='Periodic Table')
249168
fig.update_traces(
@@ -259,4 +178,4 @@ fig.show()
259178

260179
#### Reference
261180

262-
For more info on Plotly heatmaps, see: https://plotly.com/python/reference/heatmap/.<br> For more info on using colorscales with Plotly see: https://plotly.com/python/heatmap-and-contour-colorscales/ <br>For more info on `ff.create_annotated_heatmap()`, see the [full function reference](https://plotly.com/python-api-reference/generated/plotly.figure_factory.create_annotated_heatmap.html#plotly.figure_factory.create_annotated_heatmap)
181+
For more info on Plotly heatmaps, see: https://plotly.com/python/reference/heatmap/.<br> For more info on using colorscales with Plotly see: https://plotly.com/python/heatmap-and-contour-colorscales/

doc/python/choropleth-maps.md

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -349,43 +349,6 @@ fig.update_layout(
349349
fig.show()
350350
```
351351

352-
#### County Choropleth Figure Factory
353-
354-
Plotly also includes a [legacy "figure factory" for creating US county-level choropleth maps](/python/county-choropleth/).
355-
356-
```python
357-
import plotly.figure_factory as ff
358-
359-
import numpy as np
360-
import pandas as pd
361-
362-
df_sample = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/laucnty16.csv')
363-
df_sample['State FIPS Code'] = df_sample['State FIPS Code'].apply(lambda x: str(x).zfill(2))
364-
df_sample['County FIPS Code'] = df_sample['County FIPS Code'].apply(lambda x: str(x).zfill(3))
365-
df_sample['FIPS'] = df_sample['State FIPS Code'] + df_sample['County FIPS Code']
366-
367-
colorscale = ["#f7fbff", "#ebf3fb", "#deebf7", "#d2e3f3", "#c6dbef", "#b3d2e9", "#9ecae1",
368-
"#85bcdb", "#6baed6", "#57a0ce", "#4292c6", "#3082be", "#2171b5", "#1361a9",
369-
"#08519c", "#0b4083", "#08306b"
370-
]
371-
endpts = list(np.linspace(1, 12, len(colorscale) - 1))
372-
fips = df_sample['FIPS'].tolist()
373-
values = df_sample['Unemployment Rate (%)'].tolist()
374-
375-
376-
fig = ff.create_choropleth(
377-
fips=fips, values=values, scope=['usa'],
378-
binning_endpoints=endpts, colorscale=colorscale,
379-
show_state_data=False,
380-
show_hover=True,
381-
asp = 2.9,
382-
title_text = 'USA by Unemployment %',
383-
legend_title = '% unemployed'
384-
)
385-
fig.layout.template = None
386-
fig.show()
387-
```
388-
389352
#### Reference
390353

391354
See [function reference for `px.(choropleth)`](https://plotly.com/python-api-reference/generated/plotly.express.choropleth) or https://plotly.com/python/reference/choropleth/ for more information and chart attribute options!

0 commit comments

Comments
 (0)