Reputation: 3807
What is the correct way of specifying the ax where I want a chart to go?
Currently I'm trying to plot different heatmaps, each one in a different ax. But when trying this it just plots the 2 charts one on top of the other.
import seaborn as sns
import matplotlib.pyplot as plt
fig3 = plt.figure(figsize=(12,10))
ax1 = plt.subplot2grid((11,2),(0,0), rowspan=3, colspan=1)
ax2 = plt.subplot2grid((11,2),(4,0), rowspan=3, colspan=1)
ax1 = sns.heatmap(dict_pivots['df_pivot_10_win_2_thres'], square=False, cmap="RdYlBu",
linewidths=0.1, annot=True, annot_kws={"size":12})
ax2 = sns.heatmap(dict_pivots['df_pivot_5_win_2_thres'], square=False, cmap="RdYlBu",
linewidths=0.1, annot=True, annot_kws={"size":12})
Upvotes: 1
Views: 928
Reputation: 68186
You just need to pass your Axes objects to the heatmap
function:
import seaborn as sns
import matplotlib.pyplot as plt
fig3 = plt.figure(figsize=(12,10))
ax1 = plt.subplot2grid((11,2),(0,0), rowspan=3, colspan=1)
ax2 = plt.subplot2grid((11,2),(4,0), rowspan=3, colspan=1)
ax1 = sns.heatmap(dict_pivots['df_pivot_10_win_2_thres'],
square=False, cmap="RdYlBu",
linewidths=0.1, annot=True,
annot_kws={"size":12},
ax=ax1) # <-- here
ax2 = sns.heatmap(dict_pivots['df_pivot_5_win_2_thres'],
square=False, cmap="RdYlBu",
linewidths=0.1, annot=True,
annot_kws={"size":12},
ax=ax2) # <-- and here
Upvotes: 2