Skip to content

Commit c52f2fd

Browse files
committed
canvas resizing
svn path=/trunk/matplotlib/; revision=1744
1 parent 43c30f0 commit c52f2fd

File tree

5 files changed

+70
-17
lines changed

5 files changed

+70
-17
lines changed

CHANGELOG

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
New entries should be added at the top
22

3+
2005-09-09 Added support for auto canvas resizing with
4+
fig.set_figsize_inches(9,5,forward=True) # inches
5+
OR
6+
fig.resize(400,300) # pixels
7+
8+
39
2005-09-07 figure.py: update Figure.draw() to use the updated
410
renderer.draw_image() so that examples/figimage_demo.py works again.
511
examples/stock_demo.py: remove data_clipping (which no longer

lib/matplotlib/backend_bases.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,12 @@ def blit(self, bbox=None):
720720
"""
721721
pass
722722

723+
def resize(self, w, h):
724+
"""
725+
set the canvas size in pixels
726+
"""
727+
pass
728+
723729
def draw_event(self, renderer):
724730
event = DrawEvent('draw_event', self, renderer)
725731
for func in self.callbacks.get('draw_event', {}).values():

lib/matplotlib/backends/backend_gtk.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,19 @@ def __init__(self, figure):
141141

142142
self._renderer_init()
143143

144+
145+
def resize(self, w, h):
146+
'set the drawing area size in pixels'
147+
winw, winh = self.parent.parent.get_size()
148+
tmp, tmp, myw, myh = self.get_allocation()
149+
150+
padw = winw-myw
151+
padh = winh-myh
152+
153+
neww = w+padw)
154+
newh = h+padh
155+
self.parent.parent.resize(neww, newh)
156+
144157
def button_press_event(self, widget, event):
145158
if _debug: print 'FigureCanvasGTK.%s' % fn_name()
146159
x = event.x

lib/matplotlib/figure.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,22 +236,34 @@ def figimage(self, X,
236236
return im
237237

238238

239-
def set_figsize_inches(self, *args):
239+
def set_figsize_inches(self, *args, **kwargs):
240240
"""
241241
Set the figure size in inches
242242
243243
Usage: set_figsize_inches(self, w,h) OR
244244
set_figsize_inches(self, (w,h) )
245245
246+
optional kwarg forward=True will cause the canvas size to be
247+
automatically updated; eg you can resize the figure window
248+
from the shell
249+
246250
ACCEPTS: a w,h tuple with w,h in inches
247251
"""
252+
253+
forward = kwargs.get('forward', False)
248254
if len(args)==1:
249255
w,h = args[0]
250256
else:
251257
w,h = args
252258
self.figwidth.set(w)
253259
self.figheight.set(h)
254260

261+
if forward:
262+
dpival = self.dpi.get()
263+
canvasw = w*dpival
264+
canvash = h*dpival
265+
self.canvas.resize(int(canvasw), int(canvash))
266+
255267
def get_size_inches(self):
256268
return self.figwidth.get(), self.figheight.get()
257269

lib/matplotlib/finance.py

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,36 @@
2525
from pylab import gca
2626

2727

28+
29+
def parse_yahoo_historical(fh):
30+
"""
31+
Parse the historical data in file handle fh from yahoo finance and return
32+
results as a list of
33+
34+
d, open, close, high, low, volume
35+
36+
where d is a floating poing representation of date, as returned by date2num
37+
38+
"""
39+
results = []
40+
41+
42+
43+
lines = fh.readlines()
44+
for line in lines[1:]:
45+
46+
vals = line.split(',')
47+
if len(vals)!=7: continue
48+
datestr = vals[0]
49+
dt = datetime.date(*time.strptime(datestr, '%d-%b-%y')[:3])
50+
d = date2num(dt)
51+
open, high, low, close = [float(val) for val in vals[1:5]]
52+
volume = int(vals[5])
53+
54+
results.append((d, open, close, high, low, volume))
55+
results.reverse()
56+
return results
57+
2858
def quotes_historical_yahoo(ticker, date1, date2):
2959

3060
"""
@@ -49,26 +79,12 @@ def quotes_historical_yahoo(ticker, date1, date2):
4979

5080
ticker = ticker.upper()
5181

52-
results = []
53-
try:
54-
lines = urlopen(url).readlines()
82+
try: ret = parse_yahoo_historical(urlopen(url))
5583
except IOError, exc:
5684
warnings.warn('urlopen() failure\n' + url + '\n' + exc.strerror[1])
5785
return None
58-
for line in lines[1:]:
59-
60-
vals = line.split(',')
61-
if len(vals)!=7: continue
62-
datestr = vals[0]
63-
dt = datetime.date(*time.strptime(datestr, '%d-%b-%y')[:3])
64-
d = date2num(dt)
65-
open, high, low, close = [float(val) for val in vals[1:5]]
66-
volume = int(vals[5])
67-
68-
results.append((d, open, close, high, low, volume))
69-
results.reverse()
70-
return results
7186

87+
return ret
7288

7389

7490
def plot_day_summary(ax, quotes, ticksize=3,

0 commit comments

Comments
 (0)