@@ -1477,30 +1477,26 @@ class FigureFactory(object):
1477
1477
"""
1478
1478
1479
1479
@staticmethod
1480
- def _make_colorscale (colors ):
1480
+ def _make_linear_colorscale (colors ):
1481
1481
"""
1482
1482
Makes a list of colors into a colorscale-acceptable form
1483
1483
1484
1484
For documentation regarding to the form of the output, see
1485
1485
https://plot.ly/python/reference/#mesh3d-colorscale
1486
1486
"""
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 )]
1493
1489
1494
1490
@staticmethod
1495
1491
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 ):
1498
1494
"""
1499
1495
Returns figure for a 2D density plot
1500
1496
1501
1497
:param (list) x: x-axis data for plot generation
1502
1498
: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
1504
1500
or hex color, a color tuple or a list or tuple of colors. An rgb
1505
1501
color is of the form 'rgb(x, y, z)' where x, y, z belong to the
1506
1502
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,
1509
1505
members.
1510
1506
:param (int) ncontours: the number of 2D contours to draw on the plot
1511
1507
: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
1514
1510
:param (float) height: the height of the chart
1515
1511
:param (float) width: the width of the chart
1516
1512
@@ -1547,25 +1543,26 @@ def create_2D_density(x, y, colorscale='Earth', ncontours=20,
1547
1543
1548
1544
# Create a figure
1549
1545
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)
1551
1548
1552
1549
# Plot the data
1553
1550
py.iplot(fig, filename='use-parameters')
1554
1551
```
1555
1552
"""
1556
1553
from plotly .graph_objs import graph_objs
1557
1554
colorscale = FigureFactory ._validate_colors (colorscale , 'rgb' )
1558
- colorscale = FigureFactory ._make_colorscale (colorscale )
1555
+ colorscale = FigureFactory ._make_linear_colorscale (colorscale )
1559
1556
1560
- # validate hist_color and pt_color
1557
+ # validate hist_color and point_color
1561
1558
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' )
1563
1560
1564
1561
trace1 = graph_objs .Scatter (
1565
1562
x = x , y = y , mode = 'markers' , name = 'points' ,
1566
1563
marker = dict (
1567
- color = pt_color [0 ],
1568
- size = pt_size ,
1564
+ color = point_color [0 ],
1565
+ size = point_size ,
1569
1566
opacity = 0.4
1570
1567
)
1571
1568
)
0 commit comments