[英]how to show tick labels on top of matplotlib plot?
In matplotlib what is the way to have tick labels both at the bottom and in the top x axis?在 matplotlib 中,在底部和顶部 x 轴上都有刻度标签的方法是什么? I have searched a lot and still can't find how to do it.
我已经搜索了很多,但仍然找不到如何做到这一点。
Sorry, I lied in the comments. 对不起,我在评论中撒了谎。 You can do this easily (but it seems to be badly documented)
你可以很容易地做到这一点(但似乎记录很差)
fig, ax = plt.subplots(1, 1)
ax.xaxis.set_tick_params(labeltop='on')
You can do it with twiny() : 你可以用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()
Have a look to this question too for more elaborate plots. 对于更复杂的情节,也要看一下这个问题 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.