python - 如何在不添加 "ticks"的情况下从下到上移动标签

标签 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()

最佳答案

试试这个:

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

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

关于python - 如何在不添加 "ticks"的情况下从下到上移动标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51759859/

相关文章:

matplotlib绘制椭圆轮廓

plot - 对 VegaLite map 的边缘设置限制

r - 如何生成中心图

python - 在其他导入与 pep8 冲突之前需要 matplotlib.use。忽略还是修复?

python - 如何从matplotlib条形图中获取数据

r - 如何在 R、年和月中格式化轴

python - 选择第一个下拉列表后,第二个下拉列表发生变化

Python套接字绑定(bind)0.0.0.0,检查传入消息

python - 使顶级窗口跟随根 Tk 窗口

python - 使用 Clips 专家系统中的 Python 函数