如何在不添加“勾号”的情况下将标签从底部移动到顶部

时间:2018-08-09 06:06:15

标签: python matplotlib plot heatmap seaborn

我如何使用除“ tick_top”以外的其他内容将xlabel放置在图的顶部-在x标签上添加一个刻度,我不希望这样。

xlabel在底部,没有刻度: enter image description here

代码:

import numpy as np; np.random.seed(0)
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
uniform_data = np.random.rand(10, 12)
ax = sns.heatmap(uniform_data, vmin=0, vmax=1)
plt.yticks(rotation=0)
plt.show()

xlabel在顶部,但带有刻度: enter image description here

代码:

import numpy as np; np.random.seed(0)
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
uniform_data = np.random.rand(10, 12)
ax = sns.heatmap(uniform_data, vmin=0, vmax=1)
plt.yticks(rotation=0)
ax.xaxis.tick_top() # x axis on top
ax.xaxis.set_label_position('top')
plt.show()

2 个答案:

答案 0 :(得分:1)

好,终于找到了。

需要

ax.tick_params(length=0)

答案 1 :(得分:0)

尝试一下:

plt.tick_params(axis='both', which='major', labelsize=10, labelbottom = False, bottom=False, top = False, labeltop=True)

参数top = False表示没有刻度。 :)