Running my code through

Hi Team,

I am already done writing my code - did it on jupyter. I am having issues running it through I get the following error message:

Matplotlib created a temporary config/cache directory at /tmp/matplotlib-bmlk7yfc 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 “”, line 6, in
File “/home/runner/MediocreTameObservation/”, line 34, in draw_cat_plot
NameError: name ‘fig’ is not defined

Here is what an overview of my code looks like

def draw_heat_map():
# Clean the data
df_heat = df[df[‘ap_lo’] <= df[‘ap_hi’]]
df_heat = df[df[‘height’] >= df[‘height’].quantile(0.025)]
df_heat = df[df[‘height’] <= df[‘height’].quantile(0.975)]
df_heat = df[df[‘weight’] >= df[‘weight’].quantile(0.025)]
df_heat = df[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(corr)

# Set up the matplotlib figure
fig, ax = plt.subplots(figsize=(16, 12))

# Draw the heatmap with 'sns.heatmap()'
sns.heatmap(corr, mask=mask,  square=True, annot = True, annot_kws={"size": 8}, vmax= .24, fmt='0.1f')

Here is the URL for the entire code:

I appreciate your help.

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36.

Challenge: Medical Data Visualizer

Link to the challenge:

I think that error is coming from line 34. Inside that scope, you have no variable named fig. You need to create a figure in that function.

Hi Jeremy, thanks for taking your time looking into this. I am still a bit confused, isn’t the figure already created by the line

Set up the matplotlib figure

fig, ax = plt.subplots(figsize=(16, 12))??


But that’s not inside the function that is erroring.