如何在图形顶部绘制x轴?

7

棘手的问题,可能是这个例子和这个例子的组合:http://matplotlib.sourceforge.net/examples/axes_grid/simple_axisline4.html 和 http://matplotlib.sourceforge.net/examples/axes_grid/demo_axisline_style.html - Fredrik Pihl
是的,目前我只看到使用twin()的可能性。我只是想知道是否有更直接的解决方案。谢谢。 - mikeP
1个回答

10

使用

ax.xaxis.set_ticks_position("top")

例如,
import numpy as np
import matplotlib.pyplot as plt

numdata = 100
t = np.linspace(0, 100, numdata)
y = 1/t**(1/2.0)

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.xaxis.set_ticks_position('top')
ax.yaxis.grid(linestyle = '-', color = 'gray')
ax.invert_yaxis()
ax.plot(t, y, 'g-', linewidth = 1.5)

plt.show()

enter image description here


ax.yaxis.grid(True, linestyle='-') 可以添加水平线。 - jfs

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接