Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
01b0e78
refactoring FigureManagerBase to include include self in all calls to…
fariza Sep 12, 2013
ec262ad
Modified to use container for figure managers and for toolbars
fariza Sep 13, 2013
4e1d8c4
Adding standaone savefiguredialog
fariza Sep 15, 2013
a7e9968
Subplot tool and save as external clasess, working on weakref to keep…
fariza Sep 15, 2013
6c13b83
Added external buttons, trying to figure out how to keep track of them
fariza Sep 16, 2013
61d8427
Cleanup, commit to show what can be done
fariza Sep 17, 2013
b9204e5
Forgot to include external button
fariza Sep 17, 2013
0f6023e
Placing stuff in backend_bases.py and renaming rc param to single_window
fariza Sep 18, 2013
b48e903
renaming rcparam in demo
fariza Sep 18, 2013
a7ab976
adding remove_tool and move_tool
fariza Sep 18, 2013
a582aeb
Adding passthought **kwargs to add_tool, default value for buttons no…
fariza Sep 19, 2013
375f32e
adding tool for lineproperties
fariza Sep 20, 2013
5ec539f
adding saveall images from http://openiconlibrary.sourceforge.net/gal…
fariza Sep 24, 2013
ecd3c91
Adding image to saveall tool, changing order to have saveall side to …
fariza Sep 25, 2013
0f3abfe
Fixing new buttons not showing after toolbar init
fariza Sep 26, 2013
a6bc104
Saveall image uses same original filesave, the colors and motive match
fariza Sep 26, 2013
2c06a64
rebase for review
fariza Oct 23, 2013
cf80c97
pep8 correction
fariza Oct 23, 2013
7033c46
removing backedn_gtk3cairo.py from test_coding_standards
fariza Oct 23, 2013
84a1911
splitting toolbar and figuremanager examples
fariza Oct 28, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rebase for review
  • Loading branch information
fariza committed Oct 23, 2013
commit 2c06a643cf88cca601ddeebee78f16d9c4fdb03d
32 changes: 6 additions & 26 deletions examples/pylab_examples/multiple_figs_demo.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,29 @@
#!/usr/bin/env python
# Working with multiple figure windows and subplots

import matplotlib
matplotlib.use('gtk3agg')
matplotlib.rcParams['backend.single_window'] = True
from pylab import *

from matplotlib.backend_bases import ToolBase
class SampleNonGuiTool(ToolBase):
def set_figures(self, *figures):
#stupid routine that says how many axes and lines are in each
#figure
for figure in figures:
title = figure.canvas.get_window_title()
print(title)
lines = [line for ax in figure.axes for line in ax.lines]
print('Axes: %d Lines: %d' % (len(figure.axes), len(lines)))


t = arange(0.0, 2.0, 0.01)
s1 = sin(2 * pi * t)
s2 = sin(4 * pi * t)
s1 = sin(2*pi*t)
s2 = sin(4*pi*t)

figure(1)
subplot(211)
plot(t, s1)
plot(t,s1)
subplot(212)
plot(t, 2 * s1)
plot(t,2*s1)

figure(2)
plot(t, s2)
plot(t,s2)

# now switch back to figure 1 and make some changes
figure(1)
subplot(211)
plot(t, s2, 'gs')
plot(t,s2, 'gs')
setp(gca(), 'xticklabels', [])

figure(1)
savefig('fig1')
figure(2)
savefig('fig2')

figure(2).canvas.toolbar.add_tool(SampleNonGuiTool, text='Stats')



show()
84 changes: 84 additions & 0 deletions examples/user_interfaces/multifigure_backend_gtk3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import matplotlib
matplotlib.use('GTK3Agg')
matplotlib.rcParams['backend.single_window'] = True
import matplotlib.pyplot as plt
from matplotlib.backend_bases import ToolBase
import numpy as np

x = np.arange(100)

#Create 4 figures
fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
ax1.plot(x, x ** 2, marker='o', label='hey', picker=5)
ax1.legend(loc = 'lower left')

fig2 = plt.figure()
ax2 = fig2.add_subplot(111)
ax2.plot(x , np.sqrt(x))
ax2.set_xlabel('x')
ax2.set_ylabel('y')
#In the axes control tool, there is a second axes for this subplot, check it out :)
ax22 = ax2.twinx()
ax22.plot(x, -np.sqrt(x), picker=5, marker='x', label='in second axis')
ax22.set_ylabel('Minus x')

d=5
fig3 = plt.figure()
ax3 = fig3.add_subplot(111)
ax3.plot(x[::d], (x ** 3)[::d], 'ro-', label='Line label')

fig4 = plt.figure()
ax41 = fig4.add_subplot(211)
ax41.plot(x, x + 5, label='add 5')

ax42 = fig4.add_subplot(212)
ax42.plot(x, np.log(x + 15), label='add 15')

###################
#Figure management
#Change the figure1 tab label
fig1.canvas.manager.set_window_title('My first Figure')

#Change the figure manager window title
fig1.canvas.manager.set_mainwindow_title('The powerful window manager')

#Detach figure3 from the rest
fig3.canvas.manager.detach()

#Put the figure4 in the same manager as fig3
fig4.canvas.manager.reparent(fig3)

#Control the parent from the figure instantiation with the parent argument
#To place it in the same parent as fig1 we have several options
#parent=fig1
#parent=fig1.canvas.manager
#parent=fig2.canvas.manager.parent
fig5 = plt.figure(parent=fig1)
ax5 = fig5.add_subplot(111)
ax5.plot(x , x**4)
#if we want it in a separate window
#parent=False


###################
#Toolbar management
class SampleNonGuiTool(ToolBase):
text = 'Stats'
def set_figures(self, *figures):
#stupid routine that says how many axes are in each figure
for figure in figures:
title = figure.canvas.get_window_title()
print('Figure "%s": Has %d axes' % (title, len(figure.axes)))

#Add simple SampleNonGuiTool to the toolbar of fig1-fig2
fig1.canvas.manager.toolbar.add_tool(SampleNonGuiTool)

#Lets reorder the buttons in the fig3-fig4 toolbar
#Back? who needs back? my mom always told me, don't look back,
fig3.canvas.manager.toolbar.remove_tool(1)

#Move home somewhere nicer, I always wanted to live close to a rainbow
fig3.canvas.manager.toolbar.move_tool(0, 8)

plt.show()
Loading