hello,
I am working in Python with TkAgg. I have several plots that I would
like to display on a single figure. The problem is, when I set the
figure size to 12in wide, 6in high (which is perfect for my laptop) the
plots get scrunched up. If I resize the window in which they're
displayed then the plots scrunch up even further. So it appears to me
that the figure size is tied to the window size.
I would like to set the size of the initial window in which the plots
appear and then fix the size of the canvas? frame? figure? (not sure
what I need to fix). I have created a scrollbar on the window to permit
scrolling up and down.
I have attached the Navigation Toolbar to the bottom of the window,
which is where I would like it to stay. So, the plots should scroll up
and down with the toolbar fixed.
My small sample program is attached.
I am using Tk (as opposed to another GUI) as I am generating these plots
from data in SimPy and am using SimGUI to control the model execution
and plotting.
I would greatly appreciate any help!
Regards,
Bonnie Douglas
#!/usr/bin/env python
# menu-example-4.py
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
import Tkinter as Tk
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,
NavigationToolbar2TkAgg
from matplotlib.figure import Figure
from numpy import arange, sin, pi
import sys
# create toplevel window
tl=Tk.Toplevel(height='6i')
tl.title("storage")
print 'done toplevel'
# create frame
frame=Tk.Frame(master=tl, bd=2)
frame.grid_rowconfigure(0, weight=1)
frame.grid_columnconfigure(0, weight=1)
print 'frame done'
scroll = Tk.Scrollbar(frame)
scroll.grid(row=0, column=1, sticky=Tk.N+Tk.S)
# create figure
# this setting appears to control the toplevel window size as well!
# I want to set the toplevel window to 12in wide by 6 inches high
# I want to set the figure draw area to 12in wide by 18 inches high and
# let the scrollbar do the work.
# I want to keep the navigation toolbar positioned at the bottom of the
toplevel window
fig=Figure(figsize=(12,6), dpi=100)
# create plots
a1 = fig.add_subplot(411)
t = arange(0.0,3.0,0.01)
s = sin(2*pi*t)
a1.plot(t,s)
a2 = fig.add_subplot(412)
t = arange(0.0,3.0,0.01)
s = sin(2*pi*t)
a2.plot(t,s)
a3 = fig.add_subplot(413)
t = arange(0.0,3.0,0.01)
s = sin(2*pi*t)
a3.plot(t,s)
a4 = fig.add_subplot(414)
t = arange(0.0,3.0,0.01)
s = sin(2*pi*t)
a4.plot(t,s)
# create canvas
canvas=FigureCanvasTkAgg(figure=fig, master=frame)
canvas.show()
c=canvas.get_tk_widget()
c.config(bd=0, scrollregion=(0, 0, 2000, 2000), yscrollcommand=scroll.set)
c.grid(row=0, column=0, sticky=Tk.N+Tk.S+Tk.E+Tk.W)
scroll.config(command=c.yview)
# problems with toolbar not showing solved by setting the master to
# the toplevel window, not the frame!!!
toolbar=NavigationToolbar2TkAgg(canvas, tl)
toolbar.update()
#
frame.pack()
Tk.mainloop()------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users