【问题标题】:How do I remove border line between the plot and the navigation toolbar? (matplotlib with wx)如何删除绘图和导航工具栏之间的边界线? (带 wx 的 matplotlib)
【发布时间】:2018-08-23 18:02:38
【问题描述】:

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

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

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)

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

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()

非常感谢任何帮助。

【问题讨论】:

  • 你能贴出错误的截图吗?
  • 您可以将图像视为两个代码sn-ps之间的链接。问题是绘图和工具栏之间的白色边框线。
  • 你的平台是什么。在 Linux 上,我没有看到白线。
  • 我在 Windows 上。
  • @KorayBeyaz,哪个版本的 Windows?

标签: python matplotlib wxpython wxwidgets


【解决方案1】:

您可以手动编辑此文件: <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。其他版本不确定。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-31
    • 2011-10-20
    • 1970-01-01
    相关资源
    最近更新 更多