简体   繁体   English

如何设置热图的X和Y轴范围?

[英]How Can I Set The Range Of the X and Y Axis For A Heatmap?

I am trying to set the axes for both x and y but every time I try it, the heatmap shrinks to a corner of the plot. 我试图同时设置x和y的轴,但是每次尝试时,热图都会缩小到绘图的一个角。 I try 我尝试

plt.xlim(0, 60)
plt.ylim(0, 30)

I've also tried: 我也尝试过:

ax.set_ylim(0, 30)
ax.set_xlim(0, 60)

But this does the same thing. 但这确实是一样的。

Here's what I have so far to call the heatmap: 到目前为止,我将其称为热图:

pivot = df.pivot_table(index = 'Test X', columns = 'Test Y', values = 'Data')
ax = sns.heatmap(pivot, annot = True, fmt = .2g, cmap = 'Blues_r')

I want the X-axis to go from 0 - 60 and for it to show the range regardless of the data going to 60 or not and the same with y to 30. But this does not work. 我希望X轴从0到60并使其显示范围,而不管数据是否达到60,并且与y相同都变为30。但这是行不通的。

By using 通过使用

df = pd.DataFrame(np.random.random((15,15)))
sns.heatmap(df)
ax=plt.gca()
ax.set_xlim(0, 60)

I was able to get the figure with the required limits 我能够获得所需限制的数字

在此处输入图片说明

Also, ax=sns.heatmap(df); ax.set_xlim(0, 60) 另外, ax=sns.heatmap(df); ax.set_xlim(0, 60) ax=sns.heatmap(df); ax.set_xlim(0, 60) behave in the same way. ax=sns.heatmap(df); ax.set_xlim(0, 60)行为相同。 Perhaps is the way you're calling ax.set_xlim . 也许是您调用ax.set_xlim的方式。 Hope it helps 希望能帮助到你

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

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