首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在matplotlib中将x轴移动到绘图的顶部

在matplotlib中将x轴移动到绘图的顶部
EN

Stack Overflow用户
提问于 2013-01-19 03:28:44
回答 3查看 121.9K关注 0票数 136

基于this question about heatmaps in matplotlib,我想将x轴标题移动到绘图的顶部。

import matplotlib.pyplot as plt
import numpy as np
column_labels = list('ABCD')
row_labels = list('WXYZ')
data = np.random.rand(4,4)
fig, ax = plt.subplots()
heatmap = ax.pcolor(data, cmap=plt.cm.Blues)

# put the major ticks at the middle of each cell
ax.set_xticks(np.arange(data.shape[0])+0.5, minor=False)
ax.set_yticks(np.arange(data.shape[1])+0.5, minor=False)

# want a more natural, table-like display
ax.invert_yaxis()
ax.xaxis.set_label_position('top') # <-- This doesn't work!

ax.set_xticklabels(row_labels, minor=False)
ax.set_yticklabels(column_labels, minor=False)
plt.show()

然而,调用matplotlib's set_label_position (如上所述)似乎并没有达到预期的效果。下面是我的输出:

我做错了什么?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14406214

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档