Skip to content

Commit 8cf26dc

Browse files
committed
Renaming variables and optimizing _make_linear_colorscale
1 parent 7f95dcf commit 8cf26dc

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

plotly/tools.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,30 +1477,26 @@ class FigureFactory(object):
14771477
"""
14781478

14791479
@staticmethod
1480-
def _make_colorscale(colors):
1480+
def _make_linear_colorscale(colors):
14811481
"""
14821482
Makes a list of colors into a colorscale-acceptable form
14831483
14841484
For documentation regarding to the form of the output, see
14851485
https://plot.ly/python/reference/#mesh3d-colorscale
14861486
"""
1487-
colorscale = []
1488-
diff = 1./(len(colors) - 1)
1489-
1490-
for j in range(len(colors)):
1491-
colorscale.append([j * diff, colors[j]])
1492-
return colorscale
1487+
scale = 1./(len(colors) - 1)
1488+
return[[i * scale, color] for i, color in enumerate(colors)]
14931489

14941490
@staticmethod
14951491
def create_2D_density(x, y, colorscale='Earth', ncontours=20,
1496-
hist_color=(0, 0, 0.5), pt_color=(0, 0, 0.5),
1497-
pt_size=2, height=600, width=600):
1492+
hist_color=(0, 0, 0.5), point_color=(0, 0, 0.5),
1493+
point_size=2, height=600, width=600):
14981494
"""
14991495
Returns figure for a 2D density plot
15001496
15011497
:param (list) x: x-axis data for plot generation
15021498
:param (list) y: y-axis data for plot generation
1503-
:param (str|tuple|list) colormap: either a plotly scale name, an rgb
1499+
:param (str|tuple|list) colorscale: either a plotly scale name, an rgb
15041500
or hex color, a color tuple or a list or tuple of colors. An rgb
15051501
color is of the form 'rgb(x, y, z)' where x, y, z belong to the
15061502
interval [0, 255] and a color tuple is a tuple of the form
@@ -1509,8 +1505,8 @@ def create_2D_density(x, y, colorscale='Earth', ncontours=20,
15091505
members.
15101506
:param (int) ncontours: the number of 2D contours to draw on the plot
15111507
:param (str) hist_color: the color of the plotted histograms
1512-
:param (str) pt_color: the color of the scatter points
1513-
:param (str) pt_size: the color of the scatter points
1508+
:param (str) point_color: the color of the scatter points
1509+
:param (str) point_size: the color of the scatter points
15141510
:param (float) height: the height of the chart
15151511
:param (float) width: the width of the chart
15161512
@@ -1547,25 +1543,26 @@ def create_2D_density(x, y, colorscale='Earth', ncontours=20,
15471543
15481544
# Create a figure
15491545
fig = FF.create_2D_density(
1550-
x, y, colorscale=colorscale, hist_color='rgb(255, 237, 222)', pt_size=3)
1546+
x, y, colorscale=colorscale,
1547+
hist_color='rgb(255, 237, 222)', point_size=3)
15511548
15521549
# Plot the data
15531550
py.iplot(fig, filename='use-parameters')
15541551
```
15551552
"""
15561553
from plotly.graph_objs import graph_objs
15571554
colorscale = FigureFactory._validate_colors(colorscale, 'rgb')
1558-
colorscale = FigureFactory._make_colorscale(colorscale)
1555+
colorscale = FigureFactory._make_linear_colorscale(colorscale)
15591556

1560-
# validate hist_color and pt_color
1557+
# validate hist_color and point_color
15611558
hist_color = FigureFactory._validate_colors(hist_color, 'rgb')
1562-
pt_color = FigureFactory._validate_colors(pt_color, 'rgb')
1559+
point_color = FigureFactory._validate_colors(point_color, 'rgb')
15631560

15641561
trace1 = graph_objs.Scatter(
15651562
x=x, y=y, mode='markers', name='points',
15661563
marker=dict(
1567-
color=pt_color[0],
1568-
size=pt_size,
1564+
color=point_color[0],
1565+
size=point_size,
15691566
opacity=0.4
15701567
)
15711568
)

0 commit comments

Comments
 (0)