Python 在同一matplotlib图上绘制多个海生热图的问题
我在使用matplotlib和seaborn的热图时遇到了一个小问题,我无法确定问题是什么 我想在热图上显示我的数据,以及每行值的总和;但是,我无法将其添加到初始数据的右侧,因为它们的值远高于/低于我的其余数据,并且使热图无法读取 为此,我想在第一个热图的右边绘制第二个热图,只显示每行的总和 我做了以下工作:Python 在同一matplotlib图上绘制多个海生热图的问题,python,python-3.x,matplotlib,seaborn,Python,Python 3.x,Matplotlib,Seaborn,我在使用matplotlib和seaborn的热图时遇到了一个小问题,我无法确定问题是什么 我想在热图上显示我的数据,以及每行值的总和;但是,我无法将其添加到初始数据的右侧,因为它们的值远高于/低于我的其余数据,并且使热图无法读取 为此,我想在第一个热图的右边绘制第二个热图,只显示每行的总和 我做了以下工作: fig,(ax1,ax2) = plt.subplots(1,2) ax1=sns.heatmap(np.transpose(res)[::-1], cmap="RdBu_r",cent
fig,(ax1,ax2) = plt.subplots(1,2)
ax1=sns.heatmap(np.transpose(res)[::-1], cmap="RdBu_r",center=0,annot=True,fmt=".1f",xticklabels=week_arr,yticklabels=tol_arr[::-1])
ax1.set_xlabel("Week")
ax1.set_ylabel("Tolerance")
ax2 = sns.heatmap(np.transpose([np.sum(res,axis=0)]),cmap="RdBu_r",center=0)
plt.show()
但我在第二把斧头上只得到了一个热图,而第一把斧头上没有任何数据
有人知道为什么第一张热图没有出现在左边的子地块上吗
多谢各位
PS:测试数据
res=
[[-260.19999999999982,
-383.40000000001874,
-171.50000000001037,
-157.10000000000693,
-223.90000000001069],
[-333.29999999999035,
-288.10000000002884,
-387.90000000000896,
-287.6000000000015,
-267.29999999999865],
[-162.39999999999506,
-135.50000000002248,
-95.299999999992977,
31.700000000002859,
118.90000000000114],
[-464.39999999999111,
-386.20000000002841,
-305.20000000003597,
-162.40000000004926,
-225.00000000001705],
[-427.69999999996594,
-424.39999999998417,
-282.80000000000302,
-336.90000000000407,
-388.89999999999424]]
使用
ax
参数将使用plt.subplot()
创建的轴对象传递给sns.heatmap()
。这就是为什么Seaborn知道每个绘图使用哪个轴
fig,(ax1,ax2) = plt.subplots(1,2)
sns.heatmap(np.transpose(res)[::-1], cmap="RdBu_r", ax=ax1) # <-- axis arg
ax1.set_xlabel("Week")
ax1.set_ylabel("Tolerance")
sns.heatmap(np.transpose([np.sum(res,axis=0)]),cmap="RdBu_r", ax=ax2)
图(ax1,ax2)=plt.子批次(1,2)
sns.heatmap(np.transpose(res)[::-1],cmap=“RdBu_r”,ax=ax1)#通过plt.subplot()
创建的轴对象通过ax
参数传递到sns.heatmap()
。这就是为什么Seaborn知道每个绘图使用哪个轴
fig,(ax1,ax2) = plt.subplots(1,2)
sns.heatmap(np.transpose(res)[::-1], cmap="RdBu_r", ax=ax1) # <-- axis arg
ax1.set_xlabel("Week")
ax1.set_ylabel("Tolerance")
sns.heatmap(np.transpose([np.sum(res,axis=0)]),cmap="RdBu_r", ax=ax2)
图(ax1,ax2)=plt.子批次(1,2)
示例数据中不包括sns.heatmap(np.transpose(res)[::-1],cmap=“RdBu_r”,ax=ax1)#Asweek_arr
和tol_arr
,并且假设它们不是当前问题的关键组件,最好将勾号标签参数保留在绘图命令之外。或者只提供这些数组的示例。由于示例数据中不包括week_arr
和tol_arr
,并且假设它们不是当前问题的关键组件,最好不要在绘图命令中使用勾号标签参数。或者只提供这些数组的示例。