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

Skip to content

Commit 96b859f

Browse files
committed
fixed documentation
wrapped candlestick
1 parent 10adeb2 commit 96b859f

File tree

1 file changed

+95
-5
lines changed

1 file changed

+95
-5
lines changed

lib/matplotlib/finance.py

Lines changed: 95 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ def parse_yahoo_historical(fh, adjusted=True, asobject=False,
221221
holding 1-D ndarrays. The behavior of a numpy recarray is
222222
very similar to the Bunch.
223223
224-
stock_dt : `np.dtype`
225-
The data type to be used for the returned array. This is a
226-
temporary argument to easy the transition from ochl -> ohlc
224+
ochl : `bool`
225+
Temporary argument to select between ochl and ohlc ordering.
226+
Defaults to True to preserve original functionality.
227227
228228
"""
229229
if ochl:
@@ -516,6 +516,8 @@ def plot_day_summary(ax, quotes, ticksize=3,
516516
the color of the lines where close >= open
517517
colordown : color
518518
the color of the lines where close < open
519+
ochl: bool
520+
temporary argument to select between ochl and ohlc ordering
519521
520522
Returns
521523
-------
@@ -563,11 +565,49 @@ def plot_day_summary(ax, quotes, ticksize=3,
563565
return lines
564566

565567

566-
def candlestick(ax, quotes, width=0.2, colorup='k', colordown='r',
568+
def candlestick_ochl(ax, quotes, width=0.2, colorup='k', colordown='r',
567569
alpha=1.0):
568570

569571
"""
572+
Plot the time, open, close, high, low as a vertical line ranging
573+
from low to high. Use a rectangular bar to represent the
574+
open-close span. If close >= open, use colorup to color the bar,
575+
otherwise use colordown
576+
577+
Parameters
578+
----------
579+
ax : `Axes`
580+
an Axes instance to plot to
581+
quotes : sequence of (time, open, high, low, close, ...) sequences
582+
As long as the first 5 elements are these values,
583+
the record can be as long as you want (eg it may store volume).
584+
585+
time must be in float days format - see date2num
586+
587+
width : float
588+
fraction of a day for the rectangle width
589+
colorup : color
590+
the color of the rectangle where close >= open
591+
colordown : color
592+
the color of the rectangle where close < open
593+
alpha : float
594+
the rectangle alpha level
595+
596+
Returns
597+
-------
598+
ret : tuple
599+
returns (lines, patches) where lines is a list of lines
600+
added and patches is a list of the rectangle patches added
601+
602+
"""
603+
candlestick(ax, quotes, width=width, colorup=colorup, colordown=colordown,
604+
alpha=alpha, ochl=True)
605+
570606

607+
def candlestick_ohlc(ax, quotes, width=0.2, colorup='k', colordown='r',
608+
alpha=1.0):
609+
610+
"""
571611
Plot the time, open, high, low, close as a vertical line ranging
572612
from low to high. Use a rectangular bar to represent the
573613
open-close span. If close >= open, use colorup to color the bar,
@@ -598,14 +638,64 @@ def candlestick(ax, quotes, width=0.2, colorup='k', colordown='r',
598638
returns (lines, patches) where lines is a list of lines
599639
added and patches is a list of the rectangle patches added
600640
641+
"""
642+
candlestick(ax, quotes, width=width, colorup=colorup, colordown=colordown,
643+
alpha=alpha, ochl=False)
644+
645+
646+
def candlestick(ax, quotes, width=0.2, colorup='k', colordown='r',
647+
alpha=1.0, ochl=True):
648+
649+
"""
650+
651+
This function has been deprecated in 1.4 in favor of
652+
`candlestick_ochl`, which maintains the original argument
653+
order, or `candlestick_ohlc`, which uses the
654+
open-high-low-close order. This function will be removed in 1.5
655+
656+
Plot the time, open, high, low, close as a vertical line ranging
657+
from low to high. Use a rectangular bar to represent the
658+
open-close span. If close >= open, use colorup to color the bar,
659+
otherwise use colordown
660+
661+
Parameters
662+
----------
663+
ax : `Axes`
664+
an Axes instance to plot to
665+
quotes : sequence of (time, open, high, low, close, ...) sequences
666+
As long as the first 5 elements are these values,
667+
the record can be as long as you want (eg it may store volume).
668+
669+
time must be in float days format - see date2num
670+
671+
width : float
672+
fraction of a day for the rectangle width
673+
colorup : color
674+
the color of the rectangle where close >= open
675+
colordown : color
676+
the color of the rectangle where close < open
677+
alpha : float
678+
the rectangle alpha level
679+
ochl: bool
680+
temporary argument to select between ochl and ohlc ordering
681+
682+
Returns
683+
-------
684+
ret : tuple
685+
returns (lines, patches) where lines is a list of lines
686+
added and patches is a list of the rectangle patches added
687+
601688
"""
602689

603690
OFFSET = width / 2.0
604691

605692
lines = []
606693
patches = []
607694
for q in quotes:
608-
t, open, high, low, close = q[:5]
695+
if ochl:
696+
t, open, close, high, low = q[:5]
697+
else:
698+
t, open, high, low, close = q[:5]
609699

610700
if close >= open:
611701
color = colorup

0 commit comments

Comments
 (0)