2014-09-04 149 views
1

我想設置軸和y軸蜱,左側方向並在右側的方向。matplotlib組Y軸蜱

這裏有一段代碼,可以幫助你瞭解什麼,我試圖做

import wx 
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg 
from matplotlib.figure import Figure 
from matplotlib.axes import Axes 

class Frame(wx.Frame): 
    def __init__(self): 
     # initialize 
     wx.Frame.__init__(self, None) 
     # create main sizer 
     mainSizer = wx.BoxSizer(wx.VERTICAL) 
     # create figure, canvas and matplotlib toolbar 
     self.figure = Figure(figsize=(4.5,4), dpi=None) 
     self.canvas = FigureCanvasWxAgg(self, -1, self.figure) 
     # add canvas to sizer 
     mainSizer.Add(self.canvas, proportion=1, flag=wx.ALL|wx.EXPAND) 
     self.SetSizer(mainSizer) 
     mainSizer.Fit(self) 
     self.Show(True) 

app = wx.App(0)   
frame = Frame() 
axes = frame.figure.add_axes((0.1,0.1,0.8,0.8)) 

axes.tick_params(reset=True) 
axes.tick_params(axis='y',which="major", direction="in", 
       left=True,reset=False, labelleft=True) 
axes.tick_params(axis='y',which="major", direction="out", 
       right=True,reset=False, labelright=True) 

frame.canvas.draw() 

app.MainLoop() 

enter image description here

通常我想左蜱是軸內和正確的蜱被外界

回答

0

這可能是有點棘手的,其他更多的專家也許能夠深入挖掘界面以找到某些東西。同時,一種選擇是使用雙軸,以便您可以設置正確的刻度屬性,而不必擔心影響左刻度。例如。以下(其中我拿出你的代碼的相關部分):

import matplotlib.pyplot as plt 

fig = plt.figure() 
axes = fig.add_axes((0.1,0.1,0.8,0.8)) 

axes.tick_params(axis='y',which="major", direction="in", 
       left=True,reset=False, labelleft=True) 

axes2 = axes.twinx() 
axes2.tick_params(axis='y', which='major', direction='out') 

plt.show() 

如果你做這一切的時候,不過,感覺就像一個黑客攻擊,可能不是最好的選擇...

+0

謝謝,我已經想到了雙軸,但不幸的是它不適合我的情況。我寫的代碼是一個簡單的例子來說明我想要做什麼。 – Cobry 2014-09-05 02:50:56

+0

@Cobry是的,完全有道理。只是想我會提供它以防萬一。 – Ajean 2014-09-05 04:47:36