Tell us what’s happening:
I’ve passed all but one of the automated tests for the heatmap case, which checks the contents of the text in the figure to ensure the correlation results are correct with this line:
actual = [text.get_text() for text in self.ax.get_default_bbox_extra_artists() if isinstance(text, mpl.text.Text)]
The problem is that there are 3 blank text objects in my seaborn heatmap for some reason that are causing the test to fail:
Text(0.5, 1, ''), Text(0.0, 1, ''), Text(1.0, 1, '')
======================================================================
FAIL: test_heat_map_values (test_module.HeatMapTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-medical-data-visualizer/test_module.py", line 47, in test_heat_map_values
self.assertEqual(actual, expected, "Expected different values in heat map.")
AssertionError: Lists differ: ['0.0[607 chars] '0.2', '0.1', '0.1', '-0.0', '0.0', '-0.0', '0.1', '', '', ''] != ['0.0[607 chars] '0.2', '0.1', '0.1', '-0.0', '0.0', '-0.0', '0.1']
First list contains 3 additional elements.
First extra element 91:
''
Diff is 989 characters long. Set self.maxDiff to None to see it. : Expected different values in heat map.
----------------------------------------------------------------------
Ran 4 tests in 8.712s
FAILED (failures=1)
Your code so far
My heatmap drawing code is:
# Draw the heatmap with 'sns.heatmap()'
sns.set(font_scale=.5)
sns.heatmap(corr, mask=mask, annot=True, linewidth=.25, fmt='.1f', square=True, axes=ax)
print (ax.get_default_bbox_extra_artists())
which produces:
I can’t figure out where the additional text objects are coming from or how to get rid of them though.
EDIT: Additional Detail
I tried setting annot=False
and still got the empty text objects:
self.assertEqual(actual, expected, "Expected different values in heat map.")
AssertionError: Lists differ: ['', '', ''] != ['0.0', '0.0', '-0.0', '0.0', '-0.1', '0.5'[615 chars]0.1']
In fact, this time, they were the only strings I got, which suggests they aren’t annotations.
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
Challenge: Data Analysis with Python Projects - Medical Data Visualizer
Link to the challenge: