21
我一直在試圖將一個橢圓繪製到imshow圖中。它的工作原理,但圖像繪製之後繪製橢圓似乎增加XLIM和ylim,導致邊界,我想它擺脫:matplotlib:在同一軸上使用plot和imshow時的限制
注意,有直接NO白色邊框僅在調用imshow之後。
我的代碼如下:
self.dpi = 100
self.fig = Figure((6.0, 6.0), dpi=self.dpi)
self.canvas = FigureCanvas(self.fig)
self.canvas.setMinimumSize(800, 400)
self.cax = None
self.axes = self.fig.add_subplot(111)
self.axes.imshow(channel1, interpolation="nearest")
self.canvas.draw()
self.axes.plot(dat[0], dat[1], "b-")
我已經嘗試過,並呼籲「暗算」後設置的限制,沒有效果
# get limits after calling imshow
xlim, ylim = pylab.xlim(), pylab.ylim()
...
# set limits before/after calling plot
self.axes.set_xlim(xlim)
self.axes.set_ylim(ylim)
我怎麼能強迫情節不增加現有數字限制?
解決方案(感謝喬):
#for newer matplotlib versions
self.axes.imshow(channel1, interpolation="nearest")
self.axes.autoscale(False)
self.axes.plot(dat[0], dat[1], "b-")
#for older matplotlib versions (worked for me using 0.99.1.1)
self.axes.imshow(channel1, interpolation="nearest")
self.axes.plot(dat[0], dat[1], "b-", scalex=False, scaley=False)
喬您好,感謝您的詳細EXP lanation!我的matplotlib版本似乎太舊了(matplotlib .__ version__ ='0.99.1.1'),因爲它既不支持plt.subplots()也不支持ax.autoscale,但是當您指出autoscale = False時,我發現了[替代解決方案]( http://stackoverflow.com/questions/7386872/make-matplotlib-autoscaling-ignore-some-of-the-plots)修復了我的問題:每次我在最初調用imshow之後使用plot時,我都使用關鍵字參數scalex =假,scaley = False,這是正確的!謝謝! – soramimo 2012-02-03 20:30:22