[英]Python-How to have the axis ticks in both top and bottom, left and right of sns.heatmap
I am trying to draw a big heatmap with sns.heatmap function. 我正在尝试使用sns.heatmap函数绘制一个大的热图。 However, since the map is too big, it's a little hard to find the xtick label or ytick label with corresponding rows and columns. 但是,由于地图太大,因此很难找到带有相应行和列的xtick标签或ytick标签。 Can I add the xtick and xlabels also on the top and ytick and ylabels also on the right?? 我可以同时在顶部添加xtick和xlabels,也可以在右侧添加ytick和ylabel吗?
I have tried many different ways. 我尝试了许多不同的方法。 But they all didn't work. 但是他们都没有工作。
Not sure what you have tried, but the usual way would be via tick_params
: 不知道您尝试了什么,但是通常的方法是通过tick_params
:
import matplotlib.pyplot as plt
import numpy as np; np.random.seed(0)
import seaborn as sns
uniform_data = np.random.rand(10, 12)
ax = sns.heatmap(uniform_data)
ax.tick_params(right=True, top=True, labelright=True, labeltop=True)
plt.show()
Axis ticks for all sides can be placed using tick_params
from matplotlib 可以使用matplotlib中的tick_params
放置所有面的轴刻度
#Get sample correlation data to plot something. 'data' is a dataframe
corr=data.corr()
#Create Heatmap
axr = sns.heatmap(corr,cmap="coolwarm", annot=True, linewidths=.5,cbar=False)
#Set all sides
axr.tick_params(right=True, top=True, labelright=True, labeltop=True,rotation=0)
#Rotate X ticks
plt.xticks(rotation='vertical')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.