如何删除绘图和导航工具栏之间的边界线? (带有wx的matplotlib)

时间:2018-08-23 18:02:39

标签: python matplotlib wxpython wxwidgets

我正在尝试删除绘图和导航工具栏之间的边界。

我正在使用的绘图类如下。

import wx

import matplotlib as mpl
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar


class Plot(wx.Panel):
    def __init__(self, parent, id=-1, dpi=None, **kwargs):
        wx.Panel.__init__(self, parent, id=id, **kwargs)
        self.figure = mpl.figure.Figure(dpi=dpi, figsize=(2, 2))
        self.canvas = FigureCanvas(self, -1, self.figure)
        self.toolbar = NavigationToolbar(self.canvas)
        self.toolbar.Realize()
        self.axes = self.figure.add_subplot(111)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.canvas, 1, wx.EXPAND)
        sizer.Add(self.toolbar, 0, wx.RIGHT | wx.EXPAND)
        self.SetSizer(sizer)

以下是主要脚本。框架上有一个基本的正弦图,并且背景色被更改为相同。但是,导航工具栏和要删除的绘图之间有一条白色边框。这是图片。

screenshot

import wx
from matplotlib import pyplot as plt
import numpy as np

from plot_tut import Plot as myPlot

class MainWindow(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title, size=(900,600))
        self.CreateStatusBar() # A Statusbar in the bottom of the window
        self.BACKGROUND_COLOUR = wx.Colour((180,180,180))
        # Matplotlib Plot
        self.plot = myPlot(self)
        self.mainsizer = wx.BoxSizer(wx.HORIZONTAL)
        self.mainsizer.Add(self.plot, 1, wx.EXPAND)
        # call the plotting function
        self.exPlot()
        self.SetSizer(self.mainsizer)
        self.Show()
    def exPlot(self):
        t = np.arange(0.0, 3.0, 0.01)
        s = np.sin(2 *np.pi * t)

        color = (self.BACKGROUND_COLOUR.Red()/255.0,
             self.BACKGROUND_COLOUR.Green()/255.0,
             self.BACKGROUND_COLOUR.Blue()/255.0)
        self.plot.figure.set_facecolor(color)
        self.plot.axes.plot(t,s)
        self.plot.axes.set_facecolor(color)
        self.plot.toolbar.SetBackgroundColour(self.BACKGROUND_COLOUR)
        self.plot.axes.grid()

app = wx.App(False)
frame = MainWindow(None, "Sample editor")
app.MainLoop()

非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您可以手动编辑此文件: <path_to>\matplotlib\backends\backend_wx.py, line 1494

最初来自:

wx.ToolBar.__init__(self, canvas.GetParent(), -1)

收件人:

wx.ToolBar.__init__(self, canvas.GetParent(), -1, style=wx.TB_HORIZONTAL|wx.TB_NODIVIDER)

这适用于MatPlotLib 3.0.2。不确定其他版本。