Skip to content

Commit 20e0ead

Browse files
authored
plotly_express integration (#1613)
* Integrate plotly_express as plotly.express * Remove namespace package path extension * Remove doc references to ExpressFigure * move legacy plotly/colors.py to plotly/colors/__init__.py
1 parent 59e36cf commit 20e0ead

18 files changed

+4322
-4
lines changed

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,15 @@
2727
"""
2828
from __future__ import absolute_import
2929

30-
# https://packaging.python.org/guides/packaging-namespace-packages/
31-
# pkgutil-style-namespace-packages
32-
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
33-
3430
from plotly import (
3531
graph_objs,
3632
tools,
3733
utils,
3834
offline,
3935
colors,
4036
io,
37+
data,
38+
colors,
4139
_docstring_gen
4240
)
4341

Diff for: packages/python/plotly/plotly/colors.py renamed to packages/python/plotly/plotly/colors/__init__.py

+15
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@
8181

8282
from plotly import exceptions
8383

84+
85+
# Built-in qualitative color sequences and sequential,
86+
# diverging and cyclical color scales.
87+
#
88+
# Initially ported over from plotly_express
89+
from . import ( # noqa: F401
90+
qualitative,
91+
sequential,
92+
diverging,
93+
cyclical,
94+
cmocean,
95+
colorbrewer,
96+
carto,
97+
)
98+
8499
DEFAULT_PLOTLY_COLORS = ['rgb(31, 119, 180)', 'rgb(255, 127, 14)',
85100
'rgb(44, 160, 44)', 'rgb(214, 39, 40)',
86101
'rgb(148, 103, 189)', 'rgb(140, 86, 75)',

Diff for: packages/python/plotly/plotly/colors/_swatches.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
def _swatches(module_names, module_contents):
2+
"""
3+
Returns:
4+
A `Figure` object. This figure demonstrates the color scales and
5+
sequences in this module, as stacked bar charts.
6+
"""
7+
import plotly.graph_objs as go
8+
9+
sequences = [
10+
(k, v)
11+
for k, v in module_contents.items()
12+
if not (k.startswith("_") or k == "swatches")
13+
]
14+
15+
return go.Figure(
16+
data=[
17+
go.Bar(
18+
orientation="h",
19+
y=[name] * len(colors),
20+
x=[1] * len(colors),
21+
customdata=list(range(len(colors))),
22+
marker=dict(color=colors),
23+
hovertemplate="%{y}[%{customdata}] = %{marker.color}<extra></extra>",
24+
)
25+
for name, colors in reversed(sequences)
26+
],
27+
layout=dict(
28+
title=module_names,
29+
barmode="stack",
30+
barnorm="fraction",
31+
template="plotly",
32+
bargap=0.5,
33+
showlegend=False,
34+
xaxis=dict(range=[-0.02, 1.02], showticklabels=False, showgrid=False),
35+
height=max(600, 40 * len(sequences)),
36+
),
37+
)

0 commit comments

Comments
 (0)