[英]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.