Skip to main content
 首页 » 编程设计

python之Matplotlib 1.0.1 至 1.4.2

2025年05月04日13yyy_WW

我是 Python 的新手,我正在尝试调试同时使用 TKinter 和 MatPlotLib 的代码。最初,我使用 Python 2.6.2 和 MatPlotLib 1.0.1。我最近使用 MatPlotLib 1.4.2 更新到 Python 2.7……相当大的一个跳跃,一个颠簸的跳跃。

这是我的代码,它是图形界面的一部分,其中显示了一个根据用户给定的参数更新的图形:

## -- Algorithm is over, graph the results: 
self.graph = Figure() 
self.curve = self.graph.add_subplot(111, animated = TRUE, aspect = self.aspectRatio) 
self.curve.set_title(translate['my figure']) 
self.curve.set_xlabel(translate['xlabel']) 
self.curve.set_ylabel(translate['ylabel']) 
self.canvas = FigureCanvasTkAgg(self.graph, master = self.leftFrame) 
self.canvas.show() 
self.canvas.get_tk_widget().pack(pady=15) 
self.toolbar = NavigationToolbar2TkAgg(self.canvas, self.leftFrame )     
self.toolbar.update()                                    
self.canvas._tkcanvas.pack() 
self.inputBox[1][1].focus_set() 

更新到 Python 2.7 后,我在图形界面中基本上看不到任何东西,没有绘制图形。令我惊讶的是,绝对没有错误信息。

因此我认为从 MatPlotLib 1.0.1 到 1.4.2 实际绘制或显示图表的方式可能有一些修改。有什么明显的我在这里失踪了吗?任何人都可以知道 MatPlotLib 中可能发生的变化会导致此问题吗?

我希望我能更具体一些,但是没有错误消息使得调试变得非常困难...


我一直在调查这个问题,发现问题出现在从 MatPlotLib 1.0.1 到 MatPlotLib 1.1.1 的过程中,这缩小了我对发行说明的扫描范围 ( MatPlotLib, what is new in 1.1 ) 以了解发生了什么。

请您参考如下方法:

问题是您将“动画”设置为 true 而您实际上并没有制作动画(至少不是您所展示的动画)。改变

self.curve = self.graph.add_subplot(111, animated = TRUE, aspect = self.aspectRatio) 

到

self.curve = self.graph.add_subplot(111, aspect = self.aspectRatio) 

如果你想做一个动画here是一个例子。