From e80f795eeff10a4e4d7efedf91b566e73565dcf3 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Sat, 26 Jan 2019 10:00:04 -0500 Subject: [PATCH 1/2] Fix for GH 1300. There were incorrect calculations for the min/max of a 2D list. --- plotly/figure_factory/_annotated_heatmap.py | 4 +- .../test_tools/test_figure_factory.py | 91 ++++++++++++++++++- 2 files changed, 90 insertions(+), 5 deletions(-) diff --git a/plotly/figure_factory/_annotated_heatmap.py b/plotly/figure_factory/_annotated_heatmap.py index f40d7f26ba9..1c8d0229488 100644 --- a/plotly/figure_factory/_annotated_heatmap.py +++ b/plotly/figure_factory/_annotated_heatmap.py @@ -234,8 +234,8 @@ def get_z_mid(self): z_min = np.amin(self.z) z_max = np.amax(self.z) else: - z_min = min(min(self.z)) - z_max = max(max(self.z)) + z_min = min([v for row in self.z for v in row]) + z_max = max([v for row in self.z for v in row]) z_mid = (z_max+z_min) / 2 return z_mid diff --git a/plotly/tests/test_optional/test_tools/test_figure_factory.py b/plotly/tests/test_optional/test_tools/test_figure_factory.py index b3ddc298b8b..655be1570f8 100644 --- a/plotly/tests/test_optional/test_tools/test_figure_factory.py +++ b/plotly/tests/test_optional/test_tools/test_figure_factory.py @@ -773,7 +773,7 @@ def test_simple_annotated_heatmap(self): 'xref': 'x', 'y': 0, 'yref': 'y'}, - {'font': {'color': '#FFFFFF'}, + {'font': {'color': '#000000'}, 'showarrow': False, 'text': '0.5', 'x': 2, @@ -872,7 +872,7 @@ def test_annotated_heatmap_kwargs(self): 'xref': 'x', 'y': 'Three', 'yref': 'y'}, - {'font': {'color': '#000000'}, + {'font': {'color': '#FFFFFF'}, 'showarrow': False, 'text': 'sixth', 'x': 'B', @@ -951,7 +951,7 @@ def test_annotated_heatmap_reversescale(self): 'xref': 'x', 'y': 'Three', 'yref': 'y'}, - {'font': {'color': '#FFFFFF'}, + {'font': {'color': '#000000'}, 'showarrow': False, 'text': 'sixth', 'x': 'B', @@ -972,6 +972,91 @@ def test_annotated_heatmap_reversescale(self): self.assert_fig_equal(a['layout'], expected_a['layout']) + def test_bug_1300(self): + # https://github.com/plotly/plotly.py/issues/1300 + sub_z = [ + [0.1, 0.0, 0.0], + [0.0, 1.0, 0.1]] + + # sub_z = sub_z.tolist() + + # Standard scale direction + fig = ff.create_annotated_heatmap( + sub_z, colorscale='Greens', showscale=True, reversescale=True) + + expected = graph_objs.Figure({ + 'data': [{'colorscale': 'Greens', + 'reversescale': True, + 'showscale': True, + 'type': 'heatmap', + 'uid': 'baeae9f0-d650-4507-99ba-97226bb8fe6c', + 'z': [[0.1, 0., 0.], + [0., 1., 0.1]]}], + 'layout': { + 'annotations': [ + {'font': {'color': '#000000'}, + 'showarrow': False, + 'text': '0.1', + 'x': 0, + 'xref': 'x', + 'y': 0, + 'yref': 'y'}, + {'font': {'color': '#000000'}, + 'showarrow': False, + 'text': '0.0', + 'x': 1, + 'xref': 'x', + 'y': 0, + 'yref': 'y'}, + {'font': {'color': '#000000'}, + 'showarrow': False, + 'text': '0.0', + 'x': 2, + 'xref': 'x', + 'y': 0, + 'yref': 'y'}, + {'font': {'color': '#000000'}, + 'showarrow': False, + 'text': '0.0', + 'x': 0, + 'xref': 'x', + 'y': 1, + 'yref': 'y'}, + {'font': {'color': '#FFFFFF'}, + 'showarrow': False, + 'text': '1.0', + 'x': 1, + 'xref': 'x', + 'y': 1, + 'yref': 'y'}, + {'font': {'color': '#000000'}, + 'showarrow': False, + 'text': '0.1', + 'x': 2, + 'xref': 'x', + 'y': 1, + 'yref': 'y'} + ], + 'xaxis': { + 'gridcolor': 'rgb(0, 0, 0)', + 'showticklabels': False, + 'side': 'top', + 'ticks': ''}, + 'yaxis': { + 'showticklabels': False, + 'ticks': '', + 'ticksuffix': ' '}} + }) + + # Remove uids + for trace in fig.data: + trace.update(uid=None) + for trace in expected.data: + trace.update(uid=None) + + # Perform comparison + self.assert_fig_equal(fig, expected) + class TestTable(TestCase, NumpyTestUtilsMixin): From 188c4d3073b0f55dbc68c1bd9506e54e7ce9a326 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Sat, 26 Jan 2019 10:25:06 -0500 Subject: [PATCH 2/2] Python 2 future division --- plotly/figure_factory/_annotated_heatmap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plotly/figure_factory/_annotated_heatmap.py b/plotly/figure_factory/_annotated_heatmap.py index 1c8d0229488..605b7d825e9 100644 --- a/plotly/figure_factory/_annotated_heatmap.py +++ b/plotly/figure_factory/_annotated_heatmap.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import +from __future__ import absolute_import, division from plotly import exceptions, optional_imports import plotly.colors as clrs