我正在使用seaborn来绘制热图。但是如果有太多的ytick,其中一些会自动隐藏。结果如下所示:

如你所见,yticks只显示1,3,5,7....31,33如何让seaborn或matplotlib显示所有它们,如: 1,2,3,4...31,32,33,34?
我的代码是:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
y = np.random.randint(1, 100, 510)
y = y.reshape((34,15))
df = pd.DataFrame(y, columns=[x for x in 'wwwwwwwwwwwwwww'], index=['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34'])
sns.heatmap(df, annot=True)
plt.yticks(rotation=0)
plt.show()发布于 2017-08-16 16:19:56
Seaborn heatmap提供了参数
xticklabels, yticklabels:“auto”,bool,类似列表,或int,可选
如果为True,则绘制数据帧的列名。如果为False,则不绘制列名。如果类似于列表,则将这些备用标签绘制为xticklabels。如果是整数,则使用列名,但仅每n个标签绘制一次。如果为“auto”,请尝试密集绘制不重叠的标签。
因此,最简单的解决方案是添加yticklabels=1作为参数。
sns.heatmap(df, annot=True, yticklabels=1)

https://stackoverflow.com/questions/45708277
复制相似问题