Trying to build some intuition of how plotting works in seaborn (and overall).
Data
df = pd.DataFrame(dict(categorical_1=['apple', 'banana', 'grapes',
'apple', 'banana', 'grapes',
'apple', 'banana', 'grapes'],
categorical_2=['A','A','A','B','B','B','C','C','C'],
value=[10,2,5,7,3,15,1,6,8]))
pivot_table = df.pivot("categorical_1", "categorical_2", "value")
Running the following code it works fine (i.e. I get a heatmap)
fig, ax = plt.subplots(figsize=(5,5))
sns.heatmap(data=pivot_table,
cmap=sns.color_palette("Blues"),
ax=ax)
plt.show()
But when I split it up and first run
fig, ax = plt.subplots(figsize=(5,5))
and then executing
sns.heatmap(data=pivot_table,
cmap=sns.color_palette("Blues"),
ax=ax)
plt.show()
This doesn't return anything for me? Just trying to understand why that is, the ax object still exists and is being passed into the heatmap function, why would this make a difference? If I call "fig" instead it shows it fine. There are a few of these behaviors when plotting in python that surprises me and slows everything down. I've tried this in a few different environment, and executing the code all together vs doing one part of the time has the same result (plot showing vs no plot showing)