Skip to content

Fix annotated heatmap text color when values are specified as a nested list #1411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions plotly/figure_factory/_annotated_heatmap.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down
91 changes: 88 additions & 3 deletions plotly/tests/test_optional/test_tools/test_figure_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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):

Expand Down