Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 17d2705

Browse files
committed
fixed some finance mod bugs
svn path=/trunk/matplotlib/; revision=5330
1 parent 7426f7f commit 17d2705

1 file changed

Lines changed: 13 additions & 52 deletions

File tree

lib/matplotlib/finance.py

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def plot_day_summary2(ax, opens, closes, highs, lows, ticksize=4,
335335

336336
scale = ax.figure.dpi * (1.0/72.0)
337337

338-
tickTransform = Affine2D().scaled(scale, 0.0)
338+
tickTransform = Affine2D().scale(scale, 0.0)
339339

340340
r,g,b = colorConverter.to_rgb(colorup)
341341
colorup = r,g,b,1
@@ -411,24 +411,14 @@ def candlestick2(ax, opens, closes, highs, lows, width=4,
411411

412412
# note this code assumes if any value open, close, low, high is
413413
# missing they all are missing
414-
right = width/2.0
415-
left = -width/2.0
416-
417-
barVerts = [ ( (left, 0), (left, close-open), (right, close-open), (right, 0) ) for open, close in zip(opens, closes) if open != -1 and close!=-1 ]
414+
415+
delta = width/2.
416+
barVerts = [ ( (i-delta, open), (i-delta, close), (i+delta, close), (i+delta, open) ) for i, open, close in zip(xrange(len(opens)), opens, closes) if open != -1 and close!=-1 ]
418417

419418
rangeSegments = [ ((i, low), (i, high)) for i, low, high in zip(xrange(len(lows)), lows, highs) if low != -1 ]
420419

421420

422421

423-
offsetsBars = [ (i, open) for i,open in zip(xrange(len(opens)), opens) if open != -1 ]
424-
425-
sx = ax.figure.dpi * (1.0/72.0) # scale for points
426-
sy = (ax.bbox.ur().y() - ax.bbox.ll().y()) / (ax.viewLim.ur().y() - ax.viewLim.ll().y())
427-
428-
barTransform = Affine2D().scaled(sx,sy)
429-
430-
431-
432422
r,g,b = colorConverter.to_rgb(colorup)
433423
colorup = r,g,b,alpha
434424
r,g,b = colorConverter.to_rgb(colordown)
@@ -440,8 +430,6 @@ def candlestick2(ax, opens, closes, highs, lows, width=4,
440430

441431

442432
assert(len(barVerts)==len(rangeSegments))
443-
assert(len(rangeSegments)==len(offsetsBars))
444-
assert(len(offsetsBars)==len(colors))
445433

446434
useAA = 0, # use tuple here
447435
lw = 0.5, # and here
@@ -457,19 +445,13 @@ def candlestick2(ax, opens, closes, highs, lows, width=4,
457445
edgecolors = ( (0,0,0,1), ),
458446
antialiaseds = useAA,
459447
linewidths = lw,
460-
offsets = offsetsBars,
461-
transOffset = ax.transData,
462448
)
463-
barCollection.set_transform(barTransform)
464-
465-
466449

467-
468-
minpy, maxx = (0, len(rangeSegments))
450+
minx, maxx = 0, len(rangeSegments)
469451
miny = min([low for low in lows if low !=-1])
470452
maxy = max([high for high in highs if high != -1])
471453

472-
corners = (minpy, miny), (maxx, maxy)
454+
corners = (minx, miny), (maxx, maxy)
473455
ax.update_datalim(corners)
474456
ax.autoscale_view()
475457

@@ -504,38 +486,17 @@ def volume_overlay(ax, opens, closes, volumes,
504486
}
505487
colors = [colord[open<close] for open, close in zip(opens, closes) if open!=-1 and close !=-1]
506488

507-
right = width/2.0
508-
left = -width/2.0
509-
510-
511-
bars = [ ( (left, 0), (left, v), (right, v), (right, 0)) for v in volumes if v != -1 ]
512-
513-
sx = ax.figure.dpi * (1.0/72.0) # scale for points
514-
sy = (ax.bbox.ur().y() - ax.bbox.ll().y()) / (ax.viewLim.ur().y() - ax.viewLim.ll().y())
515-
516-
barTransform = Affine2D().scaled(sx,sy)
517-
518-
offsetsBars = [ (i, 0) for i,v in enumerate(volumes) if v != -1 ]
489+
delta = width/2.
490+
bars = [ ( (i-delta, 0), (i-delta, v), (i+delta, v), (i+delta, 0)) for i, v in enumerate(volumes) if v != -1 ]
519491

520492
barCollection = PolyCollection(bars,
521493
facecolors = colors,
522494
edgecolors = ( (0,0,0,1), ),
523495
antialiaseds = (0,),
524496
linewidths = (0.5,),
525-
offsets = offsetsBars,
526-
transOffset = ax.transData,
527497
)
528-
barCollection.set_transform(barTransform)
529-
530-
531-
532-
533498

534-
535-
minpy, maxx = (0, len(offsetsBars))
536-
miny = 0
537-
maxy = max([v for v in volumes if v!=-1])
538-
corners = (minpy, miny), (maxx, maxy)
499+
corners = (0, 0), (len(bars), max(volumes))
539500
ax.update_datalim(corners)
540501
ax.autoscale_view()
541502

@@ -601,9 +562,9 @@ def volume_overlay3(ax, quotes,
601562
bars = [ ( (left, 0), (left, volume), (right, volume), (right, 0)) for d, open, close, high, low, volume in quotes]
602563

603564
sx = ax.figure.dpi * (1.0/72.0) # scale for points
604-
sy = (ax.bbox.ur().y() - ax.bbox.ll().y()) / (ax.viewLim.ur().y() - ax.viewLim.ll().y())
565+
sy = ax.bbox.height / ax.viewLim.height
605566

606-
barTransform = Affine2D().scaled(sx,sy)
567+
barTransform = Affine2D().scale(sx,sy)
607568

608569
dates = [d for d, open, close, high, low, volume in quotes]
609570
offsetsBars = [(d, 0) for d in dates]
@@ -661,9 +622,9 @@ def index_bar(ax, vals,
661622
bars = [ ( (left, 0), (left, v), (right, v), (right, 0)) for v in vals if v != -1 ]
662623

663624
sx = ax.figure.dpi * (1.0/72.0) # scale for points
664-
sy = (ax.bbox.ur().y() - ax.bbox.ll().y()) / (ax.viewLim.ur().y() - ax.viewLim.ll().y())
625+
sy = ax.bbox.height / ax.viewLim.height
665626

666-
barTransform = Affine2D().scaled(sx,sy)
627+
barTransform = Affine2D().scale(sx,sy)
667628

668629
offsetsBars = [ (i, 0) for i,v in enumerate(vals) if v != -1 ]
669630

0 commit comments

Comments
 (0)