我有一幅使用
以下是我创建图表的方法:
现在,我使用
在程序中这个功能很好(在图像上显示线条),但是当我尝试使用
保存后的图像应该是这样的(保存为PNG格式):
但是我得到了这个:
以下是我用来保存图像的代码:
有什么想法,为什么保存的只是线条所在的图片,而不是我画的线条?
谢谢。
编辑:这里有一个SSCCE:http://pastebin.com/VQG165k0(只需更改保存位置和要加载的图像)。
figure.savefig(path)
保存的matplotlib图表。这个命令会将画布上显示的图片保存在图表中,但不会保存覆盖在图片上的线条。以下是我创建图表的方法:
if new:
y, x = self.model.get_image_shape()
self.figure = Figure(figsize=(x*2/72.0, y*2/72.0), dpi=72)
self.canvas = FigureCanvasWxAgg(self.scroll, -1, self.figure)
self.canvas.SetBackgroundColour('grey')
self.axes = self.figure.add_axes([0.0, 0.0, 1.0, 1.0])
self.axes.set_axis_off()
self.axes.imshow(self.model.get_image(), aspect='auto')
self.axes.set_autoscale_on(False)
self.mpl_bindings()
y, = self.scroll.GetSizeTuple()[-1:]
iHt, = self.model.get_image_shape()[:-1]
self.aspect = (float(y)/float(iHt)) # zoom factor (0.0 - 1.0)
self.controller.resize_image() # Resizes our figure according to the zoom factor
现在,我使用
draw_artist
方法在画布上绘制如下内容:def draw_polylines(self, adjustable, locked):
if self.tmp_line: self.axes.draw_artist(self.tmp_line)
for polyline in self.polylines:
for line in polyline.lines:
self.axes.draw_artist(line)
if adjustable:
for vertex in polyline.verticies:
self.axes.draw_artist(vertex)
self.axes.draw_artist(polyline.label)
在程序中这个功能很好(在图像上显示线条),但是当我尝试使用
savefig()
函数时,只有图像被保存,而没有线条。保存后的图像应该是这样的(保存为PNG格式):
![image with lines](https://istack.dev59.com/U4ysI.webp)
![after saving (without lines)](https://istack.dev59.com/GBovH.webp)
self.view.figure.savefig(dialog.GetPath(), dpi=self.view.figure.dpi)
有什么想法,为什么保存的只是线条所在的图片,而不是我画的线条?
谢谢。
编辑:这里有一个SSCCE:http://pastebin.com/VQG165k0(只需更改保存位置和要加载的图像)。
class View(wx.Frame):
,在我的另一个类中,我将其实例化为:self.view = dicom_view.View(self, self.model)
,其中self
是我的控制器,self.model
是我的模型,我可以从中获取所有图像信息。 - adchildsaxes.add_artist
将艺术家添加到轴上? - pelsonself.axes.add_artist(line)
和self.axes.add_artist(vertex)
以及self.axes.add_artist(polyline.label)
。 - adchildsaxes.plot
,所以不需要使用add_artist
。 - pelson