@@ -1578,7 +1578,7 @@ def _validate_streamline(x, y):
1578
1578
"evenly spaced array" )
1579
1579
1580
1580
@staticmethod
1581
- def _validate_annotated_heatmap (z , text ):
1581
+ def _validate_annotated_heatmap (z , annotation_text ):
1582
1582
"""
1583
1583
Annotated heatmap specific validations
1584
1584
@@ -1590,10 +1590,10 @@ def _validate_annotated_heatmap(z, text):
1590
1590
:raises: (PlotlyError) If z and text matrices are not the same
1591
1591
dimmensions.
1592
1592
"""
1593
- if text :
1594
- FigureFactory ._validate_equal_length (z , text )
1593
+ if annotation_text :
1594
+ FigureFactory ._validate_equal_length (z , annotation_text )
1595
1595
for lst in range (len (z )):
1596
- if len (z [lst ]) != len (text [lst ]):
1596
+ if len (z [lst ]) != len (annotation_text [lst ]):
1597
1597
raise exceptions .PlotlyError ("z and text should have the "
1598
1598
"same dimmensions" )
1599
1599
@@ -2562,8 +2562,10 @@ def create_dendrogram(X, orientation="bottom", labels=None,
2562
2562
'data' : dendrogram .data }
2563
2563
2564
2564
@staticmethod
2565
- def create_annotated_heatmap (z , x = None , y = None , text = [], hover_text = [],
2566
- fontcolor = [], showscale = False , ** kwargs ):
2565
+ def create_annotated_heatmap (z , x = None , y = None , annotation_text = None ,
2566
+ colorscale = None , fontcolor = None ,
2567
+ showscale = False , reversescale = False ,
2568
+ ** kwargs ):
2567
2569
"""
2568
2570
BETA function that creates annotated heatmaps
2569
2571
@@ -2602,16 +2604,22 @@ def create_annotated_heatmap(z, x=None, y=None, text=[], hover_text=[],
2602
2604
"""
2603
2605
# TODO: protected until #282
2604
2606
from plotly .graph_objs import graph_objs
2605
- FigureFactory ._validate_annotated_heatmap (z , text )
2606
- annotations = _AnnotatedHeatmap (z , x , y , text , fontcolor ,
2607
+
2608
+ # Avoiding mutables in the call signature
2609
+ annotation_text = \
2610
+ annotation_text if annotation_text is not None else []
2611
+ fontcolor = fontcolor if fontcolor is not None else []
2612
+ FigureFactory ._validate_annotated_heatmap (z , annotation_text )
2613
+ annotations = _AnnotatedHeatmap (z , x , y , annotation_text ,
2614
+ colorscale , fontcolor , reversescale ,
2607
2615
** kwargs ).make_annotations ()
2608
2616
2609
2617
if x or y :
2610
2618
trace = dict (type = 'heatmap' ,
2611
2619
z = z ,
2612
2620
x = x ,
2613
2621
y = y ,
2614
- text = hover_text ,
2622
+ colorscale = colorscale ,
2615
2623
showscale = showscale ,
2616
2624
** kwargs )
2617
2625
layout = dict (annotations = annotations ,
@@ -2621,8 +2629,7 @@ def create_annotated_heatmap(z, x=None, y=None, text=[], hover_text=[],
2621
2629
else :
2622
2630
trace = dict (type = 'heatmap' ,
2623
2631
z = z ,
2624
- text = hover_text ,
2625
- hoverinfo = 'text' ,
2632
+ colorscale = colorscale ,
2626
2633
showscale = showscale ,
2627
2634
** kwargs )
2628
2635
layout = dict (annotations = annotations ,
@@ -2637,8 +2644,7 @@ def create_annotated_heatmap(z, x=None, y=None, text=[], hover_text=[],
2637
2644
return graph_objs .Figure (data = data , layout = layout )
2638
2645
2639
2646
@staticmethod
2640
- def create_table (text , colorscale = [[0 , '#66b2ff' ], [.5 , '#e6e6e6' ],
2641
- [1 , '#ffffff' ]], fontcolor = ['#000000' ],
2647
+ def create_table (table_text , colorscale = None , fontcolor = ['#000000' ],
2642
2648
height_constant = 30 , index = False , index_title = '' ,
2643
2649
hoverinfo = 'none' , ** kwargs ):
2644
2650
"""
@@ -2698,17 +2704,23 @@ def create_table(text, colorscale=[[0, '#66b2ff'], [.5, '#e6e6e6'],
2698
2704
"""
2699
2705
# TODO: protected until #282
2700
2706
from plotly .graph_objs import graph_objs
2701
- FigureFactory ._validate_table (text , fontcolor )
2702
- table_matrix = _Table (text , colorscale , fontcolor , index , index_title ,
2703
- ** kwargs ).get_table_matrix ()
2704
- annotations = _Table (text , colorscale , fontcolor , index , index_title ,
2705
- ** kwargs ).make_table_annotations ()
2707
+
2708
+ colorscale = \
2709
+ colorscale if colorscale is not None else [[0 , '#66b2ff' ],
2710
+ [.5 , '#e6e6e6' ],
2711
+ [1 , '#ffffff' ]]
2712
+ FigureFactory ._validate_table (table_text , fontcolor )
2713
+ table_matrix = _Table (table_text , colorscale , fontcolor , index ,
2714
+ index_title , ** kwargs ).get_table_matrix ()
2715
+ annotations = _Table (table_text , colorscale , fontcolor , index ,
2716
+ index_title , ** kwargs ).make_table_annotations ()
2706
2717
2707
2718
trace = dict (type = 'heatmap' ,
2708
2719
z = table_matrix ,
2709
2720
opacity = .7 ,
2710
2721
colorscale = colorscale ,
2711
2722
showscale = False ,
2723
+ hoverinfo = hoverinfo ,
2712
2724
** kwargs )
2713
2725
2714
2726
data = [trace ]
@@ -3669,10 +3681,10 @@ class _AnnotatedHeatmap(FigureFactory):
3669
3681
"""
3670
3682
Refer to TraceFactory.create_annotated_heatmap() for docstring
3671
3683
"""
3672
- def __init__ (self , z , x = [], y = [], text = [],
3673
- fontcolor = [], colorscale = [],
3674
- reversescale = False , ** kwargs ):
3684
+ def __init__ (self , z , x , y , annotation_text , colorscale ,
3685
+ fontcolor , reversescale , ** kwargs ):
3675
3686
from plotly .graph_objs import graph_objs
3687
+
3676
3688
self .z = z
3677
3689
if x :
3678
3690
self .x = x
@@ -3682,14 +3694,11 @@ def __init__(self, z, x=[], y=[], text=[],
3682
3694
self .y = y
3683
3695
else :
3684
3696
self .y = range (len (z ))
3685
- if text :
3686
- self .text = text
3687
- else :
3688
- self .text = self .z
3689
- if colorscale :
3690
- self .colorscale = colorscale
3697
+ if annotation_text :
3698
+ self .annotation_text = annotation_text
3691
3699
else :
3692
- self .colorscale = 'RdBu'
3700
+ self .annotation_text = self .z
3701
+ self .colorscale = colorscale if colorscale is not None else 'Reds'
3693
3702
self .reversescale = reversescale
3694
3703
self .fontcolor = fontcolor
3695
3704
@@ -3768,7 +3777,7 @@ def make_annotations(self):
3768
3777
for m , val in enumerate (row ):
3769
3778
annotations .append (
3770
3779
graph_objs .Annotation (
3771
- text = str (self .text [n ][m ]),
3780
+ text = str (self .annotation_text [n ][m ]),
3772
3781
x = self .x [m ],
3773
3782
y = self .y [n ],
3774
3783
xref = 'x1' ,
@@ -3784,24 +3793,24 @@ class _Table(FigureFactory):
3784
3793
"""
3785
3794
Refer to TraceFactory.create_table() for docstring
3786
3795
"""
3787
- def __init__ (self , text , colorscale , fontcolor , index , index_title = '' ,
3788
- ** kwargs ):
3796
+ def __init__ (self , table_text , colorscale , fontcolor , index ,
3797
+ index_title = '' , ** kwargs ):
3789
3798
from plotly .graph_objs import graph_objs
3790
- if _pandas_imported and isinstance (text , pd .DataFrame ):
3791
- headers = text .columns .tolist ()
3792
- text_index = text .index .tolist ()
3793
- text = text .values .tolist ()
3794
- text .insert (0 , headers )
3799
+ if _pandas_imported and isinstance (table_text , pd .DataFrame ):
3800
+ headers = table_text .columns .tolist ()
3801
+ table_text_index = table_text .index .tolist ()
3802
+ table_text = table_text .values .tolist ()
3803
+ table_text .insert (0 , headers )
3795
3804
if index :
3796
- text_index .insert (0 , index_title )
3797
- for i in range (len (text )):
3798
- text [i ].insert (0 , text_index [i ])
3799
- self .text = text
3805
+ table_text_index .insert (0 , index_title )
3806
+ for i in range (len (table_text )):
3807
+ table_text [i ].insert (0 , table_text_index [i ])
3808
+ self .table_text = table_text
3800
3809
self .colorscale = colorscale
3801
3810
self .fontcolor = fontcolor
3802
3811
self .index = index
3803
- self .x = range (len (text [0 ]))
3804
- self .y = range (len (text ))
3812
+ self .x = range (len (table_text [0 ]))
3813
+ self .y = range (len (table_text ))
3805
3814
3806
3815
def get_table_matrix (self ):
3807
3816
'''
@@ -3810,14 +3819,14 @@ def get_table_matrix(self):
3810
3819
:rtype (list[list]) table_matrix: z matrix to make heatmap with striped
3811
3820
table coloring.
3812
3821
'''
3813
- header = [0 ] * len (self .text [0 ])
3814
- odd_row = [.5 ] * len (self .text [0 ])
3815
- even_row = [1 ] * len (self .text [0 ])
3816
- table_matrix = [None ] * len (self .text )
3822
+ header = [0 ] * len (self .table_text [0 ])
3823
+ odd_row = [.5 ] * len (self .table_text [0 ])
3824
+ even_row = [1 ] * len (self .table_text [0 ])
3825
+ table_matrix = [None ] * len (self .table_text )
3817
3826
table_matrix [0 ] = header
3818
- for i in range (1 , len (self .text ), 2 ):
3827
+ for i in range (1 , len (self .table_text ), 2 ):
3819
3828
table_matrix [i ] = odd_row
3820
- for i in range (2 , len (self .text ), 2 ):
3829
+ for i in range (2 , len (self .table_text ), 2 ):
3821
3830
table_matrix [i ] = even_row
3822
3831
if self .index :
3823
3832
for array in table_matrix :
@@ -3835,15 +3844,15 @@ def get_table_fontcolor(self):
3835
3844
:rtype (list) all_font_color: list of fontcolors for each row in table.
3836
3845
'''
3837
3846
if len (self .fontcolor ) == 1 :
3838
- all_font_color = self .fontcolor * len (self .text )
3847
+ all_font_color = self .fontcolor * len (self .table_text )
3839
3848
elif len (self .fontcolor ) == 3 :
3840
- all_font_color = range (len (self .text ))
3849
+ all_font_color = range (len (self .table_text ))
3841
3850
all_font_color [0 ] = self .fontcolor [0 ]
3842
- for i in range (1 , len (self .text ), 2 ):
3851
+ for i in range (1 , len (self .table_text ), 2 ):
3843
3852
all_font_color [i ] = self .fontcolor [1 ]
3844
- for i in range (2 , len (self .text ), 2 ):
3853
+ for i in range (2 , len (self .table_text ), 2 ):
3845
3854
all_font_color [i ] = self .fontcolor [2 ]
3846
- elif len (self .fontcolor ) == len (self .text ):
3855
+ elif len (self .fontcolor ) == len (self .table_text ):
3847
3856
all_font_color = self .fontcolor
3848
3857
return all_font_color
3849
3858
@@ -3858,7 +3867,7 @@ def make_table_annotations(self):
3858
3867
table_matrix = _Table .get_table_matrix (self )
3859
3868
all_font_color = _Table .get_table_fontcolor (self )
3860
3869
annotations = []
3861
- for n , row in enumerate (self .text ):
3870
+ for n , row in enumerate (self .table_text ):
3862
3871
for m , val in enumerate (row ):
3863
3872
annotations .append (
3864
3873
graph_objs .Annotation (
0 commit comments