如何使用“tick_top”以外的其他内容将 xlabel 放置在绘图顶部 - 这会在 x 标签上添加一个勾号,但我不想要它。
代码:
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()
代码:
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/