Skip to content

Commit 15aff13

Browse files
authored
Fix annotated heatmap text color when values are specified as a nested list (#1411)
* Fix for GH 1300. There were incorrect calculations for the min/max of a 2D list. * Python 2 future division
1 parent 7fa25ae commit 15aff13

File tree

2 files changed

+91
-6
lines changed

2 files changed

+91
-6
lines changed

Diff for: plotly/figure_factory/_annotated_heatmap.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from __future__ import absolute_import
1+
from __future__ import absolute_import, division
22

33
from plotly import exceptions, optional_imports
44
import plotly.colors as clrs
@@ -234,8 +234,8 @@ def get_z_mid(self):
234234
z_min = np.amin(self.z)
235235
z_max = np.amax(self.z)
236236
else:
237-
z_min = min(min(self.z))
238-
z_max = max(max(self.z))
237+
z_min = min([v for row in self.z for v in row])
238+
z_max = max([v for row in self.z for v in row])
239239
z_mid = (z_max+z_min) / 2
240240
return z_mid
241241

Diff for: plotly/tests/test_optional/test_tools/test_figure_factory.py

+88-3
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ def test_simple_annotated_heatmap(self):
773773
'xref': 'x',
774774
'y': 0,
775775
'yref': 'y'},
776-
{'font': {'color': '#FFFFFF'},
776+
{'font': {'color': '#000000'},
777777
'showarrow': False,
778778
'text': '0.5',
779779
'x': 2,
@@ -872,7 +872,7 @@ def test_annotated_heatmap_kwargs(self):
872872
'xref': 'x',
873873
'y': 'Three',
874874
'yref': 'y'},
875-
{'font': {'color': '#000000'},
875+
{'font': {'color': '#FFFFFF'},
876876
'showarrow': False,
877877
'text': 'sixth',
878878
'x': 'B',
@@ -951,7 +951,7 @@ def test_annotated_heatmap_reversescale(self):
951951
'xref': 'x',
952952
'y': 'Three',
953953
'yref': 'y'},
954-
{'font': {'color': '#FFFFFF'},
954+
{'font': {'color': '#000000'},
955955
'showarrow': False,
956956
'text': 'sixth',
957957
'x': 'B',
@@ -972,6 +972,91 @@ def test_annotated_heatmap_reversescale(self):
972972
self.assert_fig_equal(a['layout'],
973973
expected_a['layout'])
974974

975+
def test_bug_1300(self):
976+
# https://github.com/plotly/plotly.py/issues/1300
977+
sub_z = [
978+
[0.1, 0.0, 0.0],
979+
[0.0, 1.0, 0.1]]
980+
981+
# sub_z = sub_z.tolist()
982+
983+
# Standard scale direction
984+
fig = ff.create_annotated_heatmap(
985+
sub_z, colorscale='Greens', showscale=True, reversescale=True)
986+
987+
expected = graph_objs.Figure({
988+
'data': [{'colorscale': 'Greens',
989+
'reversescale': True,
990+
'showscale': True,
991+
'type': 'heatmap',
992+
'uid': 'baeae9f0-d650-4507-99ba-97226bb8fe6c',
993+
'z': [[0.1, 0., 0.],
994+
[0., 1., 0.1]]}],
995+
'layout': {
996+
'annotations': [
997+
{'font': {'color': '#000000'},
998+
'showarrow': False,
999+
'text': '0.1',
1000+
'x': 0,
1001+
'xref': 'x',
1002+
'y': 0,
1003+
'yref': 'y'},
1004+
{'font': {'color': '#000000'},
1005+
'showarrow': False,
1006+
'text': '0.0',
1007+
'x': 1,
1008+
'xref': 'x',
1009+
'y': 0,
1010+
'yref': 'y'},
1011+
{'font': {'color': '#000000'},
1012+
'showarrow': False,
1013+
'text': '0.0',
1014+
'x': 2,
1015+
'xref': 'x',
1016+
'y': 0,
1017+
'yref': 'y'},
1018+
{'font': {'color': '#000000'},
1019+
'showarrow': False,
1020+
'text': '0.0',
1021+
'x': 0,
1022+
'xref': 'x',
1023+
'y': 1,
1024+
'yref': 'y'},
1025+
{'font': {'color': '#FFFFFF'},
1026+
'showarrow': False,
1027+
'text': '1.0',
1028+
'x': 1,
1029+
'xref': 'x',
1030+
'y': 1,
1031+
'yref': 'y'},
1032+
{'font': {'color': '#000000'},
1033+
'showarrow': False,
1034+
'text': '0.1',
1035+
'x': 2,
1036+
'xref': 'x',
1037+
'y': 1,
1038+
'yref': 'y'}
1039+
],
1040+
'xaxis': {
1041+
'gridcolor': 'rgb(0, 0, 0)',
1042+
'showticklabels': False,
1043+
'side': 'top',
1044+
'ticks': ''},
1045+
'yaxis': {
1046+
'showticklabels': False,
1047+
'ticks': '',
1048+
'ticksuffix': ' '}}
1049+
})
1050+
1051+
# Remove uids
1052+
for trace in fig.data:
1053+
trace.update(uid=None)
1054+
for trace in expected.data:
1055+
trace.update(uid=None)
1056+
1057+
# Perform comparison
1058+
self.assert_fig_equal(fig, expected)
1059+
9751060

9761061
class TestTable(TestCase, NumpyTestUtilsMixin):
9771062

0 commit comments

Comments
 (0)