Skip to content

Commit 9f62088

Browse files
more Pandas backend options
1 parent 1db86d0 commit 9f62088

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

Diff for: CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
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.9.0] - unreleased
6+
7+
### Updated
8+
9+
- Added all cartesian-2d Plotly Express functions, plus `imshow` to Pandas backend with `kind` option
10+
511
## [4.8.2] - unreleased
612

713
### Fixed

Diff for: doc/python/pandas-backend.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ fig.show()
9898

9999
### Supported Methods
100100

101-
The Plotly backend supports the following `kind`s of Pandas plots: `scatter`, `line`, `area`, `bar`, `barh`, `hist` and `box`, via the call pattern `df.plot(kind='scatter')` or `df.plot.scatter()`. These delegate to the corresponding Plotly Express functions.
101+
The Plotly backend supports the following `kind`s of Pandas plots: `scatter`, `line`, `area`, `bar`, `barh`, `hist` and `box`, via the call pattern `df.plot(kind='scatter')` or `df.plot.scatter()`. These delegate to the corresponding Plotly Express functions. In addition, the following are valid options to the `kind` argument of `df.plot()`: `violin`, `strip`, `funnel`, `density_heatmap`, `density_contour` and `imshow`, even though the call pattern `df.plot.violin()` is not supported for these kinds of charts, per the Pandas API.
102102

103103
```python
104104
import pandas as pd
@@ -198,4 +198,4 @@ fig.show()
198198

199199
### What about Cufflinks?
200200

201-
There also exists an independent third-party wrapper library around Plotly called [Cufflinks](https://github.com/santosjorge/cufflinks), which provides similar functionality (with an API closer to that of Pandas' default `matplotlib` backend) by adding a `.iplot()` method to Pandas dataframes, as it was developed before Pandas supported configurable backends. Issues and questions regarding Cufflinks should be [raised in the Cufflinks repository](https://github.com/santosjorge/cufflinks/issues/new).
201+
There also exists an independent third-party wrapper library around Plotly called [Cufflinks](https://github.com/santosjorge/cufflinks), which provides similar functionality (with an API closer to that of Pandas' default `matplotlib` backend) by adding a `.iplot()` method to Pandas dataframes, as it was developed before Pandas supported configurable backends. Issues and questions regarding Cufflinks should be [raised in the Cufflinks repository](https://github.com/santosjorge/cufflinks/issues/new).

Diff for: packages/python/plotly/plotly/__init__.py

+33-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,20 @@ def plot(data_frame, kind, **kwargs):
8383
To activate, set pandas.options.plotting.backend="plotly"
8484
See https://github.com/pandas-dev/pandas/blob/master/pandas/plotting/__init__.py
8585
"""
86-
from .express import scatter, line, area, bar, box, histogram
86+
from .express import (
87+
scatter,
88+
line,
89+
area,
90+
bar,
91+
box,
92+
histogram,
93+
violin,
94+
strip,
95+
funnel,
96+
density_contour,
97+
density_heatmap,
98+
imshow,
99+
)
87100

88101
if kind == "scatter":
89102
new_kwargs = {k: kwargs[k] for k in kwargs if k not in ["s", "c"]}
@@ -99,9 +112,27 @@ def plot(data_frame, kind, **kwargs):
99112
if kind == "box":
100113
new_kwargs = {k: kwargs[k] for k in kwargs if k not in ["by"]}
101114
return box(data_frame, **new_kwargs)
102-
if kind in "hist":
115+
if kind in ["hist", "histogram"]:
103116
new_kwargs = {k: kwargs[k] for k in kwargs if k not in ["by", "bins"]}
104117
return histogram(data_frame, **new_kwargs)
118+
if kind == "violin":
119+
return violin(data_frame, **kwargs)
120+
if kind == "strip":
121+
return strip(data_frame, **kwargs)
122+
if kind == "funnel":
123+
return funnel(data_frame, **kwargs)
124+
if kind == "density_contour":
125+
return density_contour(data_frame, **kwargs)
126+
if kind == "density_heatmap":
127+
return density_heatmap(data_frame, **kwargs)
128+
if kind == "imshow":
129+
return imshow(data_frame, **kwargs)
130+
if kind == "heatmap":
131+
raise ValueError(
132+
"kind='heatmap' not supported plotting.backend='plotly'. "
133+
"Please use kind='imshow' or kind='density_heatmap'."
134+
)
135+
105136
raise NotImplementedError(
106137
"kind='%s' not yet supported for plotting.backend='plotly'" % kind
107138
)

Diff for: packages/python/plotly/plotly/tests/test_core/test_px/test_pandas_backend.py

+12
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@
2222
(lambda df: df.boxplot(), px.box),
2323
(lambda df: df.hist(), px.histogram),
2424
(lambda df: df["A"].hist(), lambda df: px.histogram(df["A"])),
25+
(lambda df: df.plot(kind="line"), px.line),
26+
(lambda df: df.plot(kind="area"), px.area),
27+
(lambda df: df.plot(kind="bar"), px.bar),
28+
(lambda df: df.plot(kind="box"), px.box),
29+
(lambda df: df.plot(kind="hist"), px.histogram),
30+
(lambda df: df.plot(kind="histogram"), px.histogram),
31+
(lambda df: df.plot(kind="violin"), px.violin),
32+
(lambda df: df.plot(kind="strip"), px.strip),
33+
(lambda df: df.plot(kind="funnel"), px.funnel),
34+
(lambda df: df.plot(kind="density_contour"), px.density_contour),
35+
(lambda df: df.plot(kind="density_heatmap"), px.density_heatmap),
36+
(lambda df: df.plot(kind="imshow"), px.imshow),
2537
],
2638
)
2739
def test_pandas_equiv(pandas_fn, px_fn):

0 commit comments

Comments
 (0)