|
| 1 | +'''This example demonstrates how to: |
| 2 | +* Create new toolbars |
| 3 | +* Create new windows |
| 4 | +Using `matplotlib.backend_managers.ToolManager`, |
| 5 | +`matplotlib.backend_bases.WindowBase` and |
| 6 | +`matplotlib.backend_bases.ToolContainerBase` |
| 7 | +''' |
| 8 | + |
| 9 | +from __future__ import print_function |
| 10 | +import matplotlib |
| 11 | +matplotlib.use('GTK3Cairo') |
| 12 | +matplotlib.rcParams['toolbar'] = 'toolmanager' |
| 13 | +import matplotlib.pyplot as plt |
| 14 | + |
| 15 | +fig = plt.figure() |
| 16 | + |
| 17 | +# Shortcuts to FigureManager and ToolManager |
| 18 | +manager = fig.canvas.manager |
| 19 | +tool_mgr = manager.toolmanager |
| 20 | + |
| 21 | +# Create a new toolbar |
| 22 | +topbar = manager.backend.Toolbar(tool_mgr) |
| 23 | +# The options are north, east, west and south |
| 24 | +manager.window.add_element(topbar, False, 'north') |
| 25 | + |
| 26 | +# Remove some tools from the main toolbar and add them to the |
| 27 | +# new sidebar |
| 28 | +for tool in ('home', 'back', 'forward'): |
| 29 | + manager.toolbar.remove_toolitem(tool) |
| 30 | + topbar.add_tool(tool, None) |
| 31 | + |
| 32 | +plt.plot([1, 2, 3]) |
| 33 | + |
| 34 | +# Add a new window |
| 35 | +win = manager.backend.Window('Extra tools') |
| 36 | +# create a sidebar for the new window |
| 37 | +sidebar = manager.backend.Toolbar(tool_mgr) |
| 38 | +# set the direction of the sidebar |
| 39 | +# the options are horizontal and vertical |
| 40 | +sidebar.set_flow('vertical') |
| 41 | +# add the sidebar to the new window |
| 42 | +win.add_element(sidebar, False, 'west') |
| 43 | + |
| 44 | +# Add some tools to the new sidebar |
| 45 | +for tool in ('home', 'back', 'forward', 'zoom', 'pan'): |
| 46 | + sidebar.add_tool(tool, None) |
| 47 | +# show the new window |
| 48 | +win.show() |
| 49 | + |
| 50 | +plt.show() |
0 commit comments