我已成功在wxpython面板上放置了matplotlib折线图,但边距对我来说太大了。我想减少边距,以便图表将扩展到面板(或几乎扩展)。我试过self.fig.tight_layout()但它并没有减少边距
import wx
import matplotlib
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas
class GraphFrame():
def __init__(self, parent):
self.parent = parent
self.dpi = 100
self.fig = Figure((3.0, 3.0), dpi=self.dpi)
self.canvas = FigCanvas(self.parent, -1, self.fig)
self.axes = self.fig.add_subplot(111)
self.fig.tight_layout()
self.canvas.draw()
chart_panel = wx.Panel(self.main_Frame, -1)
chart = GraphFrame(chart_panel)
答案 0 :(得分:1)
在你的代码中看到tight_layout()后,我完全重写了我的答案。我希望这是你想要的行为。在这种情况下,在某种程度上,tight_layout类似的工作(在你的代码片段tight_layout并没有改变我的Windows XP盒子上的边缘)。可能wx.Frame在使用FigureCanvasWxAgg时比wx.Panel更好?
import wx
import matplotlib
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
class GraphFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, size=(300,300))
figure = Figure()
fc = FigureCanvasWxAgg(self, -1, figure)
axes = figure.add_subplot(111)
figure.tight_layout()
self.Show(True)
if __name__ == "__main__":
app = wx.PySimpleApp(0)
graphframe = GraphFrame(None)
app.MainLoop()
答案 1 :(得分:0)
您可以使用subplots_adjust方法
如以下示例
fig.subplots_adjust(left=0.1,right=0.9,bottom=0.1,top=0.9)
希望有所帮助