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