Python 带有seaborn的subplot2grid覆盖相同的ax
指定ax的正确方法是什么?我希望图表指向何处 目前我正在尝试绘制不同的热图,每个热图都在不同的ax中。但是,当尝试这一点时,它只是将两个图表一个放在另一个上面Python 带有seaborn的subplot2grid覆盖相同的ax,python,matplotlib,seaborn,Python,Matplotlib,Seaborn,指定ax的正确方法是什么?我希望图表指向何处 目前我正在尝试绘制不同的热图,每个热图都在不同的ax中。但是,当尝试这一点时,它只是将两个图表一个放在另一个上面 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.s
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})
这就是它的样子:
您只需将轴对象传递到热图功能:
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
导入seaborn作为sns
将matplotlib.pyplot作为plt导入
图3=零件图(图尺寸=(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.热图(dict_pivots['df_pivot_10_win_2_thres'],
square=False,cmap=“RdYlBu”,
线宽=0.1,annot=真,
annot_kws={“大小”:12},
ax=ax1)#您需要告诉热图要绘制的内容。请发布完整代码以便测试。建议使用twinx:ax2=ax1.twinx()然后在ax2上绘制数据并显示绘图。@mwaskom我以为我是在指定ax1和ax2吗?或者它需要在“热图”内部完成?这些只是返回值的名称。您需要将它们作为参数传递给函数…@Gabriel,但它只是sns.heatmap(…,ax=ax1)