Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1192f62

Browse files
committed
Stop using dynamically-defined objects.
IDEs hate this… besides, this is internal code. The important part is that we eventually validate our work by instantiating a `Figure`. We can use the publicly hidden `GraphObjectFactory` for this purpose.
1 parent 33534cf commit 1192f62

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

plotly/graph_objs/figure_factory.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from collections import OrderedDict
88

99
from plotly import exceptions
10-
from plotly.graph_objs import graph_objs
10+
from plotly.graph_objs.graph_objs import GraphObjectFactory
1111
from plotly.tools import (_numpy_imported, _scipy_imported,
1212
_scipy__spatial_imported,
1313
_scipy__cluster__hierarchy_imported)
@@ -284,14 +284,13 @@ def create_quiver(x, y, u, v, scale=.1, arrow_scale=.3,
284284
arrow_scale, angle).get_barbs()
285285
arrow_x, arrow_y = _Quiver(x, y, u, v, scale,
286286
arrow_scale, angle).get_quiver_arrows()
287-
quiver = graph_objs.Scatter(x=barb_x + arrow_x,
288-
y=barb_y + arrow_y,
289-
mode='lines', **kwargs)
287+
quiver = dict(x=barb_x + arrow_x, y=barb_y + arrow_y,
288+
mode='lines', **kwargs)
290289

291290
data = [quiver]
292-
layout = graph_objs.Layout(hovermode='closest')
291+
layout = dict(hovermode='closest')
293292

294-
return graph_objs.Figure(data=data, layout=layout)
293+
return GraphObjectFactory.create('figure', data=data, layout=layout)
295294

296295
@staticmethod
297296
def create_streamline(x, y, u, v,
@@ -381,7 +380,7 @@ def create_streamline(x, y, u, v,
381380
FigureFactory._validate_equal_length(u, v)
382381
FigureFactory._validate_streamline(x, y)
383382
FigureFactory._validate_positive_scalars(density=density,
384-
arrow_scale=arrow_scale)
383+
arrow_scale=arrow_scale)
385384

386385
streamline_x, streamline_y = _Streamline(x, y, u, v,
387386
density, angle,
@@ -390,14 +389,13 @@ def create_streamline(x, y, u, v,
390389
density, angle,
391390
arrow_scale).get_streamline_arrows()
392391

393-
streamline = graph_objs.Scatter(x=streamline_x + arrow_x,
394-
y=streamline_y + arrow_y,
395-
mode='lines', **kwargs)
392+
streamline = dict(x=streamline_x + arrow_x, y=streamline_y + arrow_y,
393+
mode='lines', **kwargs)
396394

397395
data = [streamline]
398-
layout = graph_objs.Layout(hovermode='closest')
396+
layout = dict(hovermode='closest')
399397

400-
return graph_objs.Figure(data=data, layout=layout)
398+
return GraphObjectFactory.create('figure', data=data, layout=layout)
401399

402400
@staticmethod
403401
def _make_increasing_ohlc(open, high, low, close, dates, **kwargs):
@@ -636,10 +634,9 @@ def create_ohlc(open, high, low, close,
636634
dates, **kwargs)
637635
data = [ohlc_incr, ohlc_decr]
638636

639-
layout = graph_objs.Layout(xaxis=dict(zeroline=False),
640-
hovermode='closest')
637+
layout = dict(xaxis=dict(zeroline=False), hovermode='closest')
641638

642-
return graph_objs.Figure(data=data, layout=layout)
639+
return GraphObjectFactory.create('figure', data=data, layout=layout)
643640

644641
@staticmethod
645642
def _make_increasing_candle(open, high, low, close, dates, **kwargs):
@@ -871,8 +868,7 @@ def create_candlestick(open, high, low, close,
871868
open, high, low, close, dates, **kwargs)
872869
data = candle_incr_data + candle_decr_data
873870

874-
layout = graph_objs.Layout()
875-
return graph_objs.Figure(data=data, layout=layout)
871+
return GraphObjectFactory.create('figure', data=data, layout={})
876872

877873
@staticmethod
878874
def create_distplot(hist_data, group_labels,
@@ -1025,7 +1021,7 @@ def create_distplot(hist_data, group_labels,
10251021
data.append(curve)
10261022
if show_rug:
10271023
data.append(rug)
1028-
layout = graph_objs.Layout(
1024+
layout = dict(
10291025
barmode='overlay',
10301026
hovermode='closest',
10311027
legend=dict(traceorder='reversed'),
@@ -1040,7 +1036,7 @@ def create_distplot(hist_data, group_labels,
10401036
dtick=1,
10411037
showticklabels=False))
10421038
else:
1043-
layout = graph_objs.Layout(
1039+
layout = dict(
10441040
barmode='overlay',
10451041
hovermode='closest',
10461042
legend=dict(traceorder='reversed'),
@@ -1052,7 +1048,7 @@ def create_distplot(hist_data, group_labels,
10521048
position=0.0))
10531049

10541050
data = sum(data, [])
1055-
return graph_objs.Figure(data=data, layout=layout)
1051+
return GraphObjectFactory.create('figure', data=data, layout=layout)
10561052

10571053
@staticmethod
10581054
def create_dendrogram(X, orientation="bottom", labels=None,
@@ -1872,7 +1868,7 @@ def __init__(self, X, orientation='bottom', labels=None, colorscale=None,
18721868
self.zero_vals.sort()
18731869

18741870
self.layout = self.set_figure_layout(width, height)
1875-
self.data = graph_objs.Data(dd_traces)
1871+
self.data = list(dd_traces)
18761872

18771873
def get_color_dict(self, colorscale):
18781874
"""
@@ -2007,11 +2003,11 @@ def get_dendrogram_traces(self, X, colorscale):
20072003
else:
20082004
ys = icoord[i]
20092005
color_key = color_list[i]
2010-
trace = graph_objs.Scatter(
2006+
trace = dict(
20112007
x=np.multiply(self.sign[self.xaxis], xs),
20122008
y=np.multiply(self.sign[self.yaxis], ys),
20132009
mode='lines',
2014-
marker=graph_objs.Marker(color=colors[color_key])
2010+
marker=dict(color=colors[color_key])
20152011
)
20162012

20172013
try:

0 commit comments

Comments
 (0)