forked from plotly/plotly.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.py
718 lines (558 loc) · 24.6 KB
/
tools.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
# -*- coding: utf-8 -*-
"""
tools
=====
Functions that USERS will possibly want access to.
"""
from __future__ import absolute_import
import json
import warnings
import six
import re
import os
from plotly import exceptions, optional_imports
from plotly.files import PLOTLY_DIR
DEFAULT_PLOTLY_COLORS = [
"rgb(31, 119, 180)",
"rgb(255, 127, 14)",
"rgb(44, 160, 44)",
"rgb(214, 39, 40)",
"rgb(148, 103, 189)",
"rgb(140, 86, 75)",
"rgb(227, 119, 194)",
"rgb(127, 127, 127)",
"rgb(188, 189, 34)",
"rgb(23, 190, 207)",
]
REQUIRED_GANTT_KEYS = ["Task", "Start", "Finish"]
PLOTLY_SCALES = {
"Greys": ["rgb(0,0,0)", "rgb(255,255,255)"],
"YlGnBu": ["rgb(8,29,88)", "rgb(255,255,217)"],
"Greens": ["rgb(0,68,27)", "rgb(247,252,245)"],
"YlOrRd": ["rgb(128,0,38)", "rgb(255,255,204)"],
"Bluered": ["rgb(0,0,255)", "rgb(255,0,0)"],
"RdBu": ["rgb(5,10,172)", "rgb(178,10,28)"],
"Reds": ["rgb(220,220,220)", "rgb(178,10,28)"],
"Blues": ["rgb(5,10,172)", "rgb(220,220,220)"],
"Picnic": ["rgb(0,0,255)", "rgb(255,0,0)"],
"Rainbow": ["rgb(150,0,90)", "rgb(255,0,0)"],
"Portland": ["rgb(12,51,131)", "rgb(217,30,30)"],
"Jet": ["rgb(0,0,131)", "rgb(128,0,0)"],
"Hot": ["rgb(0,0,0)", "rgb(255,255,255)"],
"Blackbody": ["rgb(0,0,0)", "rgb(160,200,255)"],
"Earth": ["rgb(0,0,130)", "rgb(255,255,255)"],
"Electric": ["rgb(0,0,0)", "rgb(255,250,220)"],
"Viridis": ["rgb(68,1,84)", "rgb(253,231,37)"],
}
# color constants for violin plot
DEFAULT_FILLCOLOR = "#1f77b4"
DEFAULT_HISTNORM = "probability density"
ALTERNATIVE_HISTNORM = "probability"
# Warning format
def warning_on_one_line(message, category, filename, lineno, file=None, line=None):
return "%s:%s: %s:\n\n%s\n\n" % (filename, lineno, category.__name__, message)
warnings.formatwarning = warning_on_one_line
ipython_core_display = optional_imports.get_module("IPython.core.display")
sage_salvus = optional_imports.get_module("sage_salvus")
### mpl-related tools ###
def mpl_to_plotly(fig, resize=False, strip_style=False, verbose=False):
"""Convert a matplotlib figure to new_plotly dictionary and send.
All available information about matplotlib visualizations are stored
within a matplotlib.figure.Figure object. You can create a plot in python
using matplotlib, store the figure object, and then pass this object to
the fig_to_plotly function. In the background, mplexporter is used to
crawl through the mpl figure object for appropriate information. This
information is then systematically sent to the PlotlyRenderer which
creates the JSON structure used to make new_plotly visualizations. Finally,
these dictionaries are sent to new_plotly and your browser should open up a
new tab for viewing! Optionally, if you're working in IPython, you can
set notebook=True and the PlotlyRenderer will call new_plotly.iplot instead
of new_plotly.plot to have the graph appear directly in the IPython notebook.
Note, this function gives the user access to a simple, one-line way to
render an mpl figure in new_plotly. If you need to trouble shoot, you can do
this step manually by NOT running this fuction and entereing the following:
===========================================================================
from new_plotly.matplotlylib import mplexporter, PlotlyRenderer
# create an mpl figure and store it under a varialble 'fig'
renderer = PlotlyRenderer()
exporter = mplexporter.Exporter(renderer)
exporter.run(fig)
===========================================================================
You can then inspect the JSON structures by accessing these:
renderer.layout -- a new_plotly layout dictionary
renderer.data -- a list of new_plotly data dictionaries
"""
matplotlylib = optional_imports.get_module("new_plotly.matplotlylib")
if matplotlylib:
renderer = matplotlylib.PlotlyRenderer()
matplotlylib.Exporter(renderer).run(fig)
if resize:
renderer.resize()
if strip_style:
renderer.strip_style()
if verbose:
print(renderer.msg)
return renderer.plotly_fig
else:
warnings.warn(
"To use Plotly's matplotlylib functionality, you'll need to have "
"matplotlib successfully installed with all of its dependencies. "
"You're getting this error because matplotlib or one of its "
"dependencies doesn't seem to be installed correctly."
)
### graph_objs related tools ###
def get_subplots(rows=1, columns=1, print_grid=False, **kwargs):
"""Return a dictionary instance with the subplots set in 'layout'.
Example 1:
# stack two subplots vertically
fig = tools.get_subplots(rows=2)
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x1', yaxis='y1')]
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2')]
Example 2:
# print out string showing the subplot grid you've put in the layout
fig = tools.get_subplots(rows=3, columns=2, print_grid=True)
Keywords arguments with constant defaults:
rows (kwarg, int greater than 0, default=1):
Number of rows, evenly spaced vertically on the figure.
columns (kwarg, int greater than 0, default=1):
Number of columns, evenly spaced horizontally on the figure.
horizontal_spacing (kwarg, float in [0,1], default=0.1):
Space between subplot columns. Applied to all columns.
vertical_spacing (kwarg, float in [0,1], default=0.05):
Space between subplot rows. Applied to all rows.
print_grid (kwarg, True | False, default=False):
If True, prints a tab-delimited string representation
of your plot grid.
Keyword arguments with variable defaults:
horizontal_spacing (kwarg, float in [0,1], default=0.2 / columns):
Space between subplot columns.
vertical_spacing (kwarg, float in [0,1], default=0.3 / rows):
Space between subplot rows.
"""
# TODO: protected until #282
from plotly.graph_objs import graph_objs
warnings.warn(
"tools.get_subplots is depreciated. " "Please use tools.make_subplots instead."
)
# Throw exception for non-integer rows and columns
if not isinstance(rows, int) or rows <= 0:
raise Exception("Keyword argument 'rows' " "must be an int greater than 0")
if not isinstance(columns, int) or columns <= 0:
raise Exception("Keyword argument 'columns' " "must be an int greater than 0")
# Throw exception if non-valid kwarg is sent
VALID_KWARGS = ["horizontal_spacing", "vertical_spacing"]
for key in kwargs.keys():
if key not in VALID_KWARGS:
raise Exception("Invalid keyword argument: '{0}'".format(key))
# Set 'horizontal_spacing' / 'vertical_spacing' w.r.t. rows / columns
try:
horizontal_spacing = float(kwargs["horizontal_spacing"])
except KeyError:
horizontal_spacing = 0.2 / columns
try:
vertical_spacing = float(kwargs["vertical_spacing"])
except KeyError:
vertical_spacing = 0.3 / rows
fig = dict(layout=graph_objs.Layout()) # will return this at the end
plot_width = (1 - horizontal_spacing * (columns - 1)) / columns
plot_height = (1 - vertical_spacing * (rows - 1)) / rows
plot_num = 0
for rrr in range(rows):
for ccc in range(columns):
xaxis_name = "xaxis{0}".format(plot_num + 1)
x_anchor = "y{0}".format(plot_num + 1)
x_start = (plot_width + horizontal_spacing) * ccc
x_end = x_start + plot_width
yaxis_name = "yaxis{0}".format(plot_num + 1)
y_anchor = "x{0}".format(plot_num + 1)
y_start = (plot_height + vertical_spacing) * rrr
y_end = y_start + plot_height
xaxis = dict(domain=[x_start, x_end], anchor=x_anchor)
fig["layout"][xaxis_name] = xaxis
yaxis = dict(domain=[y_start, y_end], anchor=y_anchor)
fig["layout"][yaxis_name] = yaxis
plot_num += 1
if print_grid:
print("This is the format of your plot grid!")
grid_string = ""
plot = 1
for rrr in range(rows):
grid_line = ""
for ccc in range(columns):
grid_line += "[{0}]\t".format(plot)
plot += 1
grid_string = grid_line + "\n" + grid_string
print(grid_string)
return graph_objs.Figure(fig) # forces us to validate what we just did...
def make_subplots(
rows=1,
cols=1,
shared_xaxes=False,
shared_yaxes=False,
start_cell="top-left",
print_grid=None,
**kwargs
):
"""Return an instance of new_plotly.graph_objs.Figure
with the subplots domain set in 'layout'.
Example 1:
# stack two subplots vertically
fig = tools.make_subplots(rows=2)
This is the format of your plot grid:
[ (1,1) x1,y1 ]
[ (2,1) x2,y2 ]
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2])]
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2')]
# or see Figure.append_trace
Example 2:
# subplots with shared x axes
fig = tools.make_subplots(rows=2, shared_xaxes=True)
This is the format of your plot grid:
[ (1,1) x1,y1 ]
[ (2,1) x1,y2 ]
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2])]
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], yaxis='y2')]
Example 3:
# irregular subplot layout (more examples below under 'specs')
fig = tools.make_subplots(rows=2, cols=2,
specs=[[{}, {}],
[{'colspan': 2}, None]])
This is the format of your plot grid!
[ (1,1) x1,y1 ] [ (1,2) x2,y2 ]
[ (2,1) x3,y3 - ]
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2])]
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2')]
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x3', yaxis='y3')]
Example 4:
# insets
fig = tools.make_subplots(insets=[{'cell': (1,1), 'l': 0.7, 'b': 0.3}])
This is the format of your plot grid!
[ (1,1) x1,y1 ]
With insets:
[ x2,y2 ] over [ (1,1) x1,y1 ]
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2])]
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2')]
Example 5:
# include subplot titles
fig = tools.make_subplots(rows=2, subplot_titles=('Plot 1','Plot 2'))
This is the format of your plot grid:
[ (1,1) x1,y1 ]
[ (2,1) x2,y2 ]
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2])]
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2')]
Example 6:
# Include subplot title on one plot (but not all)
fig = tools.make_subplots(insets=[{'cell': (1,1), 'l': 0.7, 'b': 0.3}],
subplot_titles=('','Inset'))
This is the format of your plot grid!
[ (1,1) x1,y1 ]
With insets:
[ x2,y2 ] over [ (1,1) x1,y1 ]
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2])]
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2')]
Keywords arguments with constant defaults:
rows (kwarg, int greater than 0, default=1):
Number of rows in the subplot grid.
cols (kwarg, int greater than 0, default=1):
Number of columns in the subplot grid.
shared_xaxes (kwarg, boolean or list, default=False)
Assign shared x axes.
If True, subplots in the same grid column have one common
shared x-axis at the bottom of the gird.
To assign shared x axes per subplot grid cell (see 'specs'),
send list (or list of lists, one list per shared x axis)
of cell index tuples.
shared_yaxes (kwarg, boolean or list, default=False)
Assign shared y axes.
If True, subplots in the same grid row have one common
shared y-axis on the left-hand side of the gird.
To assign shared y axes per subplot grid cell (see 'specs'),
send list (or list of lists, one list per shared y axis)
of cell index tuples.
start_cell (kwarg, 'bottom-left' or 'top-left', default='top-left')
Choose the starting cell in the subplot grid used to set the
domains of the subplots.
print_grid (kwarg, boolean, default=True):
If True, prints a tab-delimited string representation of
your plot grid.
Keyword arguments with variable defaults:
horizontal_spacing (kwarg, float in [0,1], default=0.2 / cols):
Space between subplot columns.
Applies to all columns (use 'specs' subplot-dependents spacing)
vertical_spacing (kwarg, float in [0,1], default=0.3 / rows):
Space between subplot rows.
Applies to all rows (use 'specs' subplot-dependents spacing)
subplot_titles (kwarg, list of strings, default=empty list):
Title of each subplot.
"" can be included in the list if no subplot title is desired in
that space so that the titles are properly indexed.
specs (kwarg, list of lists of dictionaries):
Subplot specifications.
ex1: specs=[[{}, {}], [{'colspan': 2}, None]]
ex2: specs=[[{'rowspan': 2}, {}], [None, {}]]
- Indices of the outer list correspond to subplot grid rows
starting from the bottom. The number of rows in 'specs'
must be equal to 'rows'.
- Indices of the inner lists correspond to subplot grid columns
starting from the left. The number of columns in 'specs'
must be equal to 'cols'.
- Each item in the 'specs' list corresponds to one subplot
in a subplot grid. (N.B. The subplot grid has exactly 'rows'
times 'cols' cells.)
- Use None for blank a subplot cell (or to move pass a col/row span).
- Note that specs[0][0] has the specs of the 'start_cell' subplot.
- Each item in 'specs' is a dictionary.
The available keys are:
* is_3d (boolean, default=False): flag for 3d scenes
* colspan (int, default=1): number of subplot columns
for this subplot to span.
* rowspan (int, default=1): number of subplot rows
for this subplot to span.
* l (float, default=0.0): padding left of cell
* r (float, default=0.0): padding right of cell
* t (float, default=0.0): padding right of cell
* b (float, default=0.0): padding bottom of cell
- Use 'horizontal_spacing' and 'vertical_spacing' to adjust
the spacing in between the subplots.
insets (kwarg, list of dictionaries):
Inset specifications.
- Each item in 'insets' is a dictionary.
The available keys are:
* cell (tuple, default=(1,1)): (row, col) index of the
subplot cell to overlay inset axes onto.
* is_3d (boolean, default=False): flag for 3d scenes
* l (float, default=0.0): padding left of inset
in fraction of cell width
* w (float or 'to_end', default='to_end') inset width
in fraction of cell width ('to_end': to cell right edge)
* b (float, default=0.0): padding bottom of inset
in fraction of cell height
* h (float or 'to_end', default='to_end') inset height
in fraction of cell height ('to_end': to cell top edge)
column_width (kwarg, list of numbers)
Column_width specifications
- Functions similarly to `column_width` of `new_plotly.graph_objs.Table`.
Specify a list that contains numbers where the amount of numbers in
the list is equal to `cols`.
- The numbers in the list indicate the proportions that each column
domains take across the full horizontal domain excluding padding.
- For example, if columns_width=[3, 1], horizontal_spacing=0, and
cols=2, the domains for each column would be [0. 0.75] and [0.75, 1]
row_width (kwargs, list of numbers)
Row_width specifications
- Functions similarly to `column_width`. Specify a list that contains
numbers where the amount of numbers in the list is equal to `rows`.
- The numbers in the list indicate the proportions that each row
domains take along the full vertical domain excluding padding.
- For example, if row_width=[3, 1], vertical_spacing=0, and
cols=2, the domains for each row from top to botton would be
[0. 0.75] and [0.75, 1]
"""
import plotly.subplots
warnings.warn(
"new_plotly.tools.make_subplots is deprecated, "
"please use new_plotly.subplots.make_subplots instead",
DeprecationWarning,
stacklevel=1,
)
return plotly.subplots.make_subplots(
rows=rows,
cols=cols,
shared_xaxes=shared_xaxes,
shared_yaxes=shared_yaxes,
start_cell=start_cell,
print_grid=print_grid,
**kwargs
)
warnings.filterwarnings(
"default", r"new_plotly\.tools\.make_subplots is deprecated", DeprecationWarning
)
def get_graph_obj(obj, obj_type=None):
"""Returns a new graph object.
OLD FUNCTION: this will *silently* strip out invalid pieces of the object.
NEW FUNCTION: no striping of invalid pieces anymore - only raises error
on unrecognized graph_objs
"""
# TODO: Deprecate or move. #283
from plotly.graph_objs import graph_objs
try:
cls = getattr(graph_objs, obj_type)
except (AttributeError, KeyError):
raise exceptions.PlotlyError(
"'{}' is not a recognized graph_obj.".format(obj_type)
)
return cls(obj)
def _replace_newline(obj):
"""Replaces '\n' with '<br>' for all strings in a collection."""
if isinstance(obj, dict):
d = dict()
for key, val in list(obj.items()):
d[key] = _replace_newline(val)
return d
elif isinstance(obj, list):
l = list()
for index, entry in enumerate(obj):
l += [_replace_newline(entry)]
return l
elif isinstance(obj, six.string_types):
s = obj.replace("\n", "<br>")
if s != obj:
warnings.warn(
"Looks like you used a newline character: '\\n'.\n\n"
"Plotly uses a subset of HTML escape characters\n"
"to do things like newline (<br>), bold (<b></b>),\n"
"italics (<i></i>), etc. Your newline characters \n"
"have been converted to '<br>' so they will show \n"
"up right on your Plotly figure!"
)
return s
else:
return obj # we return the actual reference... but DON'T mutate.
def return_figure_from_figure_or_data(figure_or_data, validate_figure):
from plotly.graph_objs import Figure
from plotly.basedatatypes import BaseFigure
validated = False
if isinstance(figure_or_data, dict):
figure = figure_or_data
elif isinstance(figure_or_data, list):
figure = {"data": figure_or_data}
elif isinstance(figure_or_data, BaseFigure):
figure = figure_or_data.to_dict()
validated = True
else:
raise exceptions.PlotlyError(
"The `figure_or_data` positional "
"argument must be "
"`dict`-like, `list`-like, or an instance of new_plotly.graph_objs.Figure"
)
if validate_figure and not validated:
try:
figure = Figure(**figure).to_dict()
except exceptions.PlotlyError as err:
raise exceptions.PlotlyError(
"Invalid 'figure_or_data' argument. "
"Plotly will not be able to properly "
"parse the resulting JSON. If you "
"want to send this 'figure_or_data' "
"to Plotly anyway (not recommended), "
"you can set 'validate=False' as a "
"plot option.\nHere's why you're "
"seeing this error:\n\n{0}"
"".format(err)
)
if not figure["data"]:
raise exceptions.PlotlyEmptyDataError(
"Empty data list found. Make sure that you populated the "
"list of data objects you're sending and try again.\n"
"Questions? Visit support.plot.ly"
)
return figure
# Default colours for finance charts
_DEFAULT_INCREASING_COLOR = "#3D9970" # http://clrs.cc
_DEFAULT_DECREASING_COLOR = "#FF4136"
DIAG_CHOICES = ["scatter", "histogram", "box"]
VALID_COLORMAP_TYPES = ["cat", "seq"]
# Deprecations
class FigureFactory(object):
@staticmethod
def _deprecated(old_method, new_method=None):
if new_method is None:
# The method name stayed the same.
new_method = old_method
warnings.warn(
"new_plotly.tools.FigureFactory.{} is deprecated. "
"Use new_plotly.figure_factory.{}".format(old_method, new_method)
)
@staticmethod
def create_2D_density(*args, **kwargs):
FigureFactory._deprecated("create_2D_density", "create_2d_density")
from plotly.figure_factory import create_2d_density
return create_2d_density(*args, **kwargs)
@staticmethod
def create_annotated_heatmap(*args, **kwargs):
FigureFactory._deprecated("create_annotated_heatmap")
from plotly.figure_factory import create_annotated_heatmap
return create_annotated_heatmap(*args, **kwargs)
@staticmethod
def create_candlestick(*args, **kwargs):
FigureFactory._deprecated("create_candlestick")
from plotly.figure_factory import create_candlestick
return create_candlestick(*args, **kwargs)
@staticmethod
def create_dendrogram(*args, **kwargs):
FigureFactory._deprecated("create_dendrogram")
from plotly.figure_factory import create_dendrogram
return create_dendrogram(*args, **kwargs)
@staticmethod
def create_distplot(*args, **kwargs):
FigureFactory._deprecated("create_distplot")
from plotly.figure_factory import create_distplot
return create_distplot(*args, **kwargs)
@staticmethod
def create_facet_grid(*args, **kwargs):
FigureFactory._deprecated("create_facet_grid")
from plotly.figure_factory import create_facet_grid
return create_facet_grid(*args, **kwargs)
@staticmethod
def create_gantt(*args, **kwargs):
FigureFactory._deprecated("create_gantt")
from plotly.figure_factory import create_gantt
return create_gantt(*args, **kwargs)
@staticmethod
def create_ohlc(*args, **kwargs):
FigureFactory._deprecated("create_ohlc")
from plotly.figure_factory import create_ohlc
return create_ohlc(*args, **kwargs)
@staticmethod
def create_quiver(*args, **kwargs):
FigureFactory._deprecated("create_quiver")
from plotly.figure_factory import create_quiver
return create_quiver(*args, **kwargs)
@staticmethod
def create_scatterplotmatrix(*args, **kwargs):
FigureFactory._deprecated("create_scatterplotmatrix")
from plotly.figure_factory import create_scatterplotmatrix
return create_scatterplotmatrix(*args, **kwargs)
@staticmethod
def create_streamline(*args, **kwargs):
FigureFactory._deprecated("create_streamline")
from plotly.figure_factory import create_streamline
return create_streamline(*args, **kwargs)
@staticmethod
def create_table(*args, **kwargs):
FigureFactory._deprecated("create_table")
from plotly.figure_factory import create_table
return create_table(*args, **kwargs)
@staticmethod
def create_trisurf(*args, **kwargs):
FigureFactory._deprecated("create_trisurf")
from plotly.figure_factory import create_trisurf
return create_trisurf(*args, **kwargs)
@staticmethod
def create_violin(*args, **kwargs):
FigureFactory._deprecated("create_violin")
from plotly.figure_factory import create_violin
return create_violin(*args, **kwargs)
def get_config_plotly_server_url():
"""
Function to get the .config file's 'plotly_domain' without importing
the chart_studio package. This property is needed to compute the default
value of the new_plotly.js config plotlyServerURL, so it is independent of
the chart_studio integration and still needs to live in
Returns
-------
str
"""
config_file = os.path.join(PLOTLY_DIR, ".config")
default_server_url = "https://plot.ly"
if not os.path.exists(config_file):
return default_server_url
with open(config_file, "rt") as f:
try:
config_dict = json.load(f)
if not isinstance(config_dict, dict):
config_dict = {}
except:
# TODO: issue a warning and bubble it up
config_dict = {}
return config_dict.get("plotly_domain", default_server_url)