forked from plotly/plotly.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
177 lines (147 loc) · 5.13 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
"""
https://plot.ly/python/
Plotly's Python API allows users to programmatically access Plotly's
server resources.
This package is organized as follows:
Subpackages:
- new_plotly: all functionality that requires access to Plotly's servers
- graph_objs: objects for designing figures and visualizing data
- matplotlylib: tools to convert matplotlib figures
Modules:
- tools: some helpful tools that do not require access to Plotly's servers
- utils: functions that you probably won't need, but that subpackages use
- version: holds the current API version
- exceptions: defines our custom exception classes
"""
from __future__ import absolute_import
import sys
from _plotly_utils.importers import relative_import
if sys.version_info < (3, 7):
from plotly import (
graph_objs,
tools,
utils,
offline,
colors,
io,
data,
)
from plotly.version import __version__
__all__ = [
"graph_objs",
"tools",
"utils",
"offline",
"colors",
"io",
"data",
"__version__",
]
# Set default template (for >= 3.7 this is done in ploty/io/__init__.py)
from plotly.io import templates
templates._default = "new_plotly"
else:
__all__, __getattr__, __dir__ = relative_import(
__name__,
[
".graph_objs",
".graph_objects",
".tools",
".utils",
".offline",
".colors",
".io",
".data",
],
[".version.__version__"],
)
def plot(data_frame, kind, **kwargs):
"""
Pandas plotting backend function, not meant to be called directly.
To activate, set pandas.options.plotting.backend="new_plotly"
See https://github.com/pandas-dev/pandas/blob/master/pandas/plotting/__init__.py
"""
from .express import (
scatter,
line,
area,
bar,
box,
histogram,
violin,
strip,
funnel,
density_contour,
density_heatmap,
imshow,
)
if kind == "scatter":
new_kwargs = {k: kwargs[k] for k in kwargs if k not in ["s", "c"]}
return scatter(data_frame, **new_kwargs)
if kind == "line":
return line(data_frame, **kwargs)
if kind == "area":
return area(data_frame, **kwargs)
if kind == "bar":
return bar(data_frame, **kwargs)
if kind == "barh":
return bar(data_frame, orientation="h", **kwargs)
if kind == "box":
new_kwargs = {k: kwargs[k] for k in kwargs if k not in ["by"]}
return box(data_frame, **new_kwargs)
if kind in ["hist", "histogram"]:
new_kwargs = {k: kwargs[k] for k in kwargs if k not in ["by", "bins"]}
return histogram(data_frame, **new_kwargs)
if kind == "violin":
return violin(data_frame, **kwargs)
if kind == "strip":
return strip(data_frame, **kwargs)
if kind == "funnel":
return funnel(data_frame, **kwargs)
if kind == "density_contour":
return density_contour(data_frame, **kwargs)
if kind == "density_heatmap":
return density_heatmap(data_frame, **kwargs)
if kind == "imshow":
return imshow(data_frame, **kwargs)
if kind == "heatmap":
raise ValueError(
"kind='heatmap' not supported plotting.backend='new_plotly'. "
"Please use kind='imshow' or kind='density_heatmap'."
)
raise NotImplementedError(
"kind='%s' not yet supported for plotting.backend='new_plotly'" % kind
)
def boxplot_frame(data_frame, **kwargs):
"""
Pandas plotting backend function, not meant to be called directly.
To activate, set pandas.options.plotting.backend="new_plotly"
See https://github.com/pandas-dev/pandas/blob/master/pandas/plotting/__init__.py
"""
from .express import box
skip = ["by", "column", "ax", "fontsize", "rot", "grid", "figsize", "layout"]
skip += ["return_type"]
new_kwargs = {k: kwargs[k] for k in kwargs if k not in skip}
return box(data_frame, **new_kwargs)
def hist_frame(data_frame, **kwargs):
"""
Pandas plotting backend function, not meant to be called directly.
To activate, set pandas.options.plotting.backend="new_plotly"
See https://github.com/pandas-dev/pandas/blob/master/pandas/plotting/__init__.py
"""
from .express import histogram
skip = ["column", "by", "grid", "xlabelsize", "xrot", "ylabelsize", "yrot"]
skip += ["ax", "sharex", "sharey", "figsize", "layout", "bins", "legend"]
new_kwargs = {k: kwargs[k] for k in kwargs if k not in skip}
return histogram(data_frame, **new_kwargs)
def hist_series(data_frame, **kwargs):
"""
Pandas plotting backend function, not meant to be called directly.
To activate, set pandas.options.plotting.backend="new_plotly"
See https://github.com/pandas-dev/pandas/blob/master/pandas/plotting/__init__.py
"""
from .express import histogram
skip = ["by", "grid", "xlabelsize", "xrot", "ylabelsize", "yrot", "ax"]
skip += ["figsize", "bins", "legend"]
new_kwargs = {k: kwargs[k] for k in kwargs if k not in skip}
return histogram(data_frame, **new_kwargs)