7

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

enter image description here

Image from: http://oceanographyclay1987.blogspot.com/2010/10/light-attenuation-in-ocean.html

agamesh
  • 559
  • 1
  • 10
  • 26
mikeP
  • 801
  • 2
  • 11
  • 20
  • tricky, probably a combination of [this example](http://matplotlib.sourceforge.net/examples/axes_grid/simple_axisline4.html) and [this one](http://matplotlib.sourceforge.net/examples/axes_grid/demo_axisline_style.html) – Fredrik Pihl Dec 27 '11 at 00:21
  • Yes, the use of twin() is the only possibility that I see at the moment. I was just wondering if there is a more straight forward solution. Thanks – mikeP Dec 27 '11 at 00:30

1 Answers1

10

Use

ax.xaxis.set_ticks_position("top")

For example,

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

unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677