Skip to content Skip to sidebar Skip to footer

How To Plot With X-axis At The Top Of The Figure?

I would like to ask how to produce a plot similar to that in the figure below? Basically, how to have x-axis at the top of the figure. Thanks Image from: http://oceanographyclay19

Solution 1:

Use

ax.xaxis.set_ticks_position("top")

For example,

import numpy as np
import matplotlib.pyplotas 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

Post a Comment for "How To Plot With X-axis At The Top Of The Figure?"