2012-04-27 198 views

答えて

127

使用ax.yaxis.tick_right()

:右のラベルの

from matplotlib import pyplot as plt 

f = plt.figure() 
ax = f.add_subplot(111) 
ax.yaxis.tick_right() 
plt.plot([2,3,4,5]) 
plt.show() 

enter image description here

+0

グレート答えを、あなたは1を取得し、私はあなたの写真のために別の1を与えるだろうが、私はのみに限定されましたよ1. – lukecampbell

+8

私はまた、右にイザベルを動かしたいですか? – Brian

+0

興味深いことに、これはtickyの名前がsharey = Trueによって抑制されるべきであるにもかかわらず戻ってくるのです。 – endolith

72

ax.yaxis.set_label_position("right")を使用し、すなわち:

f = plt.figure() 
ax = f.add_subplot(111) 
ax.yaxis.tick_right() 
ax.yaxis.set_label_position("right") 
plt.plot([2,3,4,5]) 
ax.set_xlabel("$x$ /mm") 
ax.set_ylabel("$y$ /mm") 
plt.show() 
38

ホアキンの答えは動作しますが、の副作用を持っていますlからダニを除去する軸の横側これを修正するには、tick_right()に電話してset_ticks_position('both')を呼び出します。改訂された例:

from matplotlib import pyplot as plt 

f = plt.figure() 
ax = f.add_subplot(111) 
ax.yaxis.tick_right() 
ax.yaxis.set_ticks_position('both') 
plt.plot([2,3,4,5]) 
plt.show() 

結果は両側にダニがあり、右側に目盛りが付いたプロットです。

enter image description here

9

念の誰かが(私が行ったように)頼む1はsubplot2gridを使用する場合、これも可能です。例えば:それは、この表示されます

import matplotlib.pyplot as plt 
plt.subplot2grid((3,2), (0,1), rowspan=3) 
plt.plot([2,3,4,5]) 
plt.tick_params(axis='y', which='both', labelleft='off', labelright='on') 
plt.show() 

enter image description here

+2

これは 'ax.tick_params(axis = 'y'、= 'both'、labelleft = 'off'、labelright = 'on')'と同様に働きます。しかし、それは 'ylabel'を動かさない – Eric

+0

' plt.command'でもラベルを移動する方法はありますか? – Ger

関連する問題