I am getting this error I don’t know why. I have checked the shape of mask and it is same as the correlation matrix.
python main.py
Matplotlib created a temporary config/cache directory at /tmp/matplotlib-r54k1e_k because the
python main.py
Matplotlib created a temporary config/cache directory at /tmp/matplotlib-z07y6363 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.
Traceback (most recent call last):
File "main.py", line 7, in <module>
medical_data_visualizer.draw_heat_map()
File "/home/runner/boilerplate-medical-data-visualizer-4/medical_data_visualizer.py", line 62, in draw_heat_map
ax = sns.heatmap(
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/seaborn/_decorators.py", line 46, in inner_f
return f(**kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/seaborn/matrix.py", line 545, in heatmap
plotter = _HeatMapper(data, vmin, vmax, cmap, center, robust, annot, fmt,
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/seaborn/matrix.py", line 112, in __init__
mask = _matrix_mask(data, mask)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/seaborn/matrix.py", line 74, in _matrix_mask
raise ValueError("Mask must have the same shape as data.")
ValueError: Mask must have the same shape as data.
exit status 1
Code
def draw_heat_map():
# Clean the data
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['weight'] <= df['weight'].quantile(0.975)) ]
# Calculate the correlation matrix
corr = df_heat.corr()
# Generate a mask for the upper triangle
mask = np.triu(np.ones_like(corr))
# Set up the matplotlib figure
fig, ax = plt.subplots(figsize = (20,10) )
# Draw the heatmap with 'sns.heatmap()'
ax = sns.heatmap(
df_heat,
linewidths=.5,
annot=True,
fmt='.1f',
mask=mask,
square=True,
center=0,
vmin=-0.08,
vmax=0.24,
cbar_kws={
'shrink': .45,
'format': '%.2f'
})
# Do not modify the next two lines
fig.savefig('heatmap.png')
return fig