2012-04-27 20 views

cevap

127

kullanın örneğin ax.yaxis.tick_right()

: sağ etiketler için

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

Güzel cevap, +1, sana resim için başka +1 verecekti olsun ama sadece sınırlı değilim 1. – lukecampbell

+8

Ylabel'i de sağa taşımak istediğim şey nedir? – Brian

+0

, bu, sharey = True – endolith

72

, ax.yaxis.set_label_position("right") yani kullanın:

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

joaquin cevabı eserlerini fakat yan etkisi yoktur l'den keneler çıkarılıyor eksenlerin eft tarafı. Bunu düzeltmek için set_ticks_position('both') numaralı aramayı tick_right() numaralı telefondan takip edin. Revize edilmiş bir örnek:

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() 

Sonuç, her iki taraftaki keneler, ancak sağdaki kene etiketleri bulunan bir çizimdir.

enter image description here

9

Sadece (benim yaptığım gibi) vaka biri sorar biri subplot2grid kullandığında bu da mümkündür. Örneğin:

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() 

Bu gösterecektir:

enter image description here

+2

Bu, ax.tick_params (axis = 'y', = 'her ikisi', labelleft = 'off', labelright = 'on') 'ile de çalışır. Ama ylabel'i hareket ettirmiyor – Eric

+0

Etiketi bir "plt.command" ile de taşımanın bir yolu var mı? – Ger

İlgili konular