Tell us what’s happening:
I feel like my program works perfectly, but there is a rounding error somewhere and i can’t figure out where, other posts on the forum said that it wasnt a rounding error but a bug that occurs with the newer matplotlib version but those bugfixes didn’t help me either.
This is what my code outputs:
python main.py
Matplotlib created a temporary config/cache directory at /tmp/matplotlib-ht9_r_6g because the default path (/config/matplotlib) is not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing.
…[‘0.0’, ‘0.0’, ‘-0.0’, ‘0.0’, ‘-0.1’, ‘0.5’, ‘0.0’, ‘0.1’, ‘0.1’, ‘0.2’, ‘0.0’, ‘0.0’, ‘0.0’, ‘0.0’, ‘0.0’, ‘0.0’, ‘0.2’, ‘0.1’, ‘0.0’, ‘0.2’, ‘0.1’, ‘0.0’, ‘0.1’, ‘-0.0’, ‘-0.1’, ‘0.1’, ‘0.0’, ‘0.2’, ‘0.0’, ‘0.1’, ‘-0.0’, ‘-0.0’, ‘0.1’, ‘0.0’, ‘0.1’, ‘0.4’, ‘-0.0’, ‘-0.0’, ‘0.3’, ‘0.2’, ‘0.1’, ‘-0.0’, ‘0.0’, ‘0.0’, ‘-0.0’, ‘-0.0’, ‘-0.0’, ‘0.2’, ‘0.1’, ‘0.1’, ‘0.0’, ‘0.0’, ‘0.0’, ‘0.0’, ‘0.3’, ‘0.0’, ‘-0.0’, ‘0.0’, ‘-0.0’, ‘-0.0’, ‘-0.0’, ‘0.0’, ‘0.0’, ‘-0.0’, ‘0.0’, ‘0.0’, ‘0.0’, ‘0.2’, ‘0.0’, ‘-0.0’, ‘0.2’, ‘0.1’, ‘0.3’, ‘0.2’, ‘0.1’, ‘-0.0’, ‘-0.0’, ‘-0.0’, ‘-0.0’, ‘0.1’, ‘-0.1’, ‘-0.1’, ‘0.6’, ‘0.0’, ‘0.2’, ‘0.1’, ‘0.1’, ‘-0.0’, ‘0.0’, ‘-0.0’, ‘0.1’]
F
FAIL: test_heat_map_values (test_module.HeatMapTestCase)
Traceback (most recent call last):
File “/home/runner/boilerplate-medical-data-visualizer/test_module.py”, line 48, in test_heat_map_values
self.assertEqual(actual, expected, “Expected different values in heat map.”)
AssertionError: Lists differ: ['0.0[59 chars], ‘0.2’, ‘0.0’, ‘0.0’, ‘0.0’, ‘0.0’, ‘0.0’, ‘0[548 chars]0.1’] != ['0.0[59 chars], ‘0.3’, ‘0.0’, ‘0.0’, ‘0.0’, ‘0.0’, ‘0.0’, ‘0[548 chars]0.1’]
First differing element 9:
‘0.2’
‘0.3’
[‘0.0’,
‘0.0’,
‘-0.0’,
‘0.0’,
‘-0.1’,
‘0.5’,
‘0.0’,
‘0.1’,
‘0.1’,
- ‘0.2’,
? ^
-
‘0.3’,
? ^‘0.0’,
‘0.0’,
‘0.0’,
‘0.0’,
‘0.0’,
‘0.0’,
‘0.2’,
‘0.1’,
‘0.0’,
‘0.2’,
‘0.1’,
‘0.0’,
‘0.1’,
‘-0.0’,
‘-0.1’,
‘0.1’,
‘0.0’,
‘0.2’,
‘0.0’,
‘0.1’,
‘-0.0’,
‘-0.0’,
‘0.1’,
‘0.0’,
‘0.1’,
‘0.4’,
‘-0.0’,
‘-0.0’,
‘0.3’,
‘0.2’,
‘0.1’,
‘-0.0’,
‘0.0’,
‘0.0’,
‘-0.0’,
‘-0.0’,
‘-0.0’,
‘0.2’,
‘0.1’,
‘0.1’,
‘0.0’,
‘0.0’,
‘0.0’,
‘0.0’,
‘0.3’,
‘0.0’,
‘-0.0’,
‘0.0’,
‘-0.0’,
‘-0.0’,
‘-0.0’,
‘0.0’,
‘0.0’,
‘-0.0’,
‘0.0’,
‘0.0’,
‘0.0’,
‘0.2’,
‘0.0’,
‘-0.0’,
‘0.2’,
‘0.1’,
‘0.3’,
‘0.2’,
‘0.1’,
‘-0.0’,
‘-0.0’,
‘-0.0’,
‘-0.0’,
‘0.1’,
‘-0.1’,
‘-0.1’,
- ‘0.6’,
? ^
-
‘0.7’,
? ^‘0.0’,
‘0.2’,
‘0.1’,
‘0.1’,
‘-0.0’,
‘0.0’,
‘-0.0’,
‘0.1’] : Expected different values in heat map.
Ran 4 tests in 6.438s
FAILED (failures=1)
Your code so far
Draws Heat Map
def draw_heat_map():
# Cleans the data for systolic pressure and height and weight
df_heat = df[(df[‘ap_lo’] <= df[‘ap_hi’]) &
(df[‘height’] >= df[‘height’].quantile(0.025)) &
(df[‘height’] <= df[‘height’].quantile(0.975)) &
(df[‘weight’] >= df[‘weight’].quantile(0.025)) &
(df[‘height’] <= df[‘height’].quantile(0.975))]
# Calculates the correlation matrix
corr = df_heat.corr()
# Generates a mask for the upper triangle
mask = np.triu(corr)
# Sets up the matplotlib figure
fig, ax = plt.subplots(figsize=(12, 12))
# Draws the heatmap with 'sns.heatmap()'
graph = sns.heatmap(corr, mask = mask, annot=True, center=0, linewidths = 1, square=True, fmt = '.1f', cbar_kws = {'shrink' : 0.5})
fig = graph.figure
# Saves the figure
fig.savefig('heatmap.png')
return fig
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36
Challenge: Medical Data Visualizer
Link to the challenge: