2011-12-26 17 views
7

私は下の図のようなプロットを作る方法を尋ねますか?基本的に、図の上部にx軸を持つ方法。おかげ図の上部にx軸をプロットするにはどうすればよいですか?

enter image description here

画像から:http://oceanographyclay1987.blogspot.com/2010/10/light-attenuation-in-ocean.html

+0

トリッキー、おそらく[この例](http://matplotlib.sourceforge.net/examples/axes_grid/simple_axisline4.html)と[this one](http://matplotlib.sourceforge.net/examples/axes_grid/)の組み合わせですdemo_axisline_style.html) –

+0

はい、twin()の使用は私が現時点で見る唯一の可能性です。より真直ぐな解決策があるのか​​どうか疑問に思っていただけです。ありがとう – mikeP

答えて

9

使用

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

+0

'ax.yaxis.grid(真、linestyle = ' - ')'水平線を追加するには – jfs

+0

うわー、ありがとう。これは優雅なやり方です。 – mikeP

+0

@ J.F.Sebastian:提案をいただきありがとうございます。 – unutbu

関連する問題