I have a Matplotlib figure with a lot of subplots which needs a ScrolledPanel. Now I want a navigation toolbar for the figure which remains static when the figure panel is scrolled. I tried adding it to another panel than the canvas's parent but that does not work(navigation toolbar remains inside canvas's parent only).
Is there any way to have the matplotlib navigation toolbar remain static but making rest of the canvas scrollable?
Here's my code:
class PlotCanvas(wx.Frame):
def __init__(self, parent, wxid, title, data):
wx.Frame.__init__(self, parent, wxid, title)
self.box_main = wx.BoxSizer(wx.VERTICAL)
panel_lower = wx.lib.scrolledpanel.ScrolledPanel(self, size=(2500,-1))
panel_lower.SetupScrolling()
panel_lower.SetBackgroundColour("White")
self.box_lower = wx.BoxSizer(wx.HORIZONTAL)
box_local = wx.BoxSizer(wx.VERTICAL)
plt = Figure(figsize=(95,10))
num_columns = len(data.columns)
axes_1 = plt.add_subplot(1, num_columns, 1)
data_numpy = data[data.columns[0]].to_numpy()
depth = data.index.to_numpy()
plt.gca().invert_yaxis()
plt.subplots_adjust(left=0.01, right=1.00, top=0.95, bottom=0.05)
axes_1.plot(data_numpy, depth)
for i in range(1, num_columns):
axes_tmp = plt.add_subplot(1, num_columns, i+1, sharey=axes_1)
axes_tmp.set(xlabel=data.columns[i], ylabel='Depth', title='Depth vs ' + data.columns[i])
data_numpy = data[data.columns[i]].to_numpy()
plt.gca().invert_yaxis()
axes_tmp.plot(data_numpy, depth)
canvas = FigureCanvas(panel_lower, -1, plt)
canvas.draw()
box_local.Add(canvas, 1, wx.EXPAND)
panel_nav = wx.Panel(self)
box_nav = wx.BoxSizer(wx.HORIZONTAL)
toolbar = NavigationToolbar(canvas)
box_nav.Add(toolbar)
panel_nav.SetSizer(box_nav)
toolbar.Realize()
self.box_main.Add(panel_nav, 0, wx.CENTER)
self.box_lower.Add(box_local, 1, wx.EXPAND)
self.box_main.Add(panel_lower, 1, wx.EXPAND)
panel_lower.SetSizer(self.box_lower)
self.SetSizer(self.box_main)
self.box_main.Layout()
from (wxpython) make the matplotlib NavigationToolbar static for a figure inside scrolledpanel
No comments:
Post a Comment