简体   繁体   English

Seaborn 1D 热图切换 x 轴和 y 轴

[英]Seaborn 1D Heatmap switch x-and y-axis

Is it possible to switch the x - and y axis in a Seaborn 1D Heatmap?是否可以在 Seaborn 1D 热图中切换x轴和y轴? The actual plot looks like:实际情节如下:

实际热图

My code for this plot is as followed:我的这个情节的代码如下:

#Histogram data
n1, bins1, patches1 = plt.hist(x_start, bins=binwidth, cumulative=False, normed=1, facecolor='#023d6b', alpha=0.8, histtype='bar',label='density random')
n2, bins2, patches2 = plt.hist(histo, bins=binwidth, cumulative=False, normed=1, facecolor='red', alpha=0.5, histtype='bar',label='density real')

df = pd.DataFrame({'Departure real': n2,'Departure model':n1},
               index= bins2[:-1]+1)

#Plot Options
fig2, ax2 =plt.subplots(figsize=(16,11))
ax2=sns.heatmap(df, annot=False, fmt="g",cmap="seismic",cbar_kws={'label': 'Probability'})
ax2.figure.axes[-1].yaxis.label.set_size(16)
ax2.set_ylabel('Hours [h]', fontsize=16)
ax2.xaxis.set_tick_params(labelsize=16)
ax2.yaxis.set_tick_params(labelsize=16)
ax2.invert_yaxis()
cax = plt.gcf().axes[-1]
cax.tick_params(labelsize=16)

So at the end Hours [h] should be on the x -axis and Departure model , Departure real on the y -axis.所以最后Hours [h]应该在x轴和Departure model上, Departure realy轴上。 I couldn't find any solution for that until now.直到现在我都找不到任何解决方案。 I don't have to use Seaborn, if there is another method to do that better.如果有另一种方法可以做得更好,我不必使用 Seaborn。

您可以转置数据框:

df=df.transpose()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM