[英]how to show tick labels on top of matplotlib plot?
在 matplotlib 中,在底部和顶部 x 轴上都有刻度标签的方法是什么? 我已经搜索了很多,但仍然找不到如何做到这一点。
对不起,我在评论中撒了谎。 你可以很容易地做到这一点(但似乎记录很差)
fig, ax = plt.subplots(1, 1)
ax.xaxis.set_tick_params(labeltop='on')
你可以用twiny()来做到这一点:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax2 = ax1.twiny()
X2tick_location= ax1.xaxis.get_ticklocs() #Get the tick locations in data coordinates as a numpy array
ax2.set_xticks(X2tick_location)
ax2.set_xticklabels(X2tick_location)
plt.show()
对于更复杂的情节,也要看一下这个问题 。
这似乎是 v3.5 的标准方式:
fig, ax = plt.subplots()
ax.tick_params('x', top=True, labeltop=True)
请注意, top
关键字绘制刻度,而labeltop
关键字绘制标签。 文档在这里。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.