Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def _candlestick(ax, quotes, width=0.2, colorup='k', colordown='r',
- alpha=1.0, ochl=True, coloredge=None):
- """
- Plot the time, open, high, low, close as a vertical line ranging
- from low to high. Use a rectangular bar to represent the
- open-close span. If close >= open, use colorup to color the bar,
- otherwise use colordown
- Parameters
- ----------
- ax : `Axes`
- an Axes instance to plot to
- quotes : sequence of quote sequences
- data to plot. time must be in float date format - see date2num
- (time, open, high, low, close, ...) vs
- (time, open, close, high, low, ...)
- set by `ochl`
- width : float
- fraction of a day for the rectangle width
- colorup : color
- the color of the rectangle where close >= open
- colordown : color
- the color of the rectangle where close < open
- alpha : float
- the rectangle alpha level
- ochl: bool
- argument to select between ochl and ohlc ordering of quotes
- coloregde : color (optional)
- the color of the edge. default is color of the candlebody
- Returns
- -------
- ret : tuple
- returns (lines, patches) where lines is a list of lines
- added and patches is a list of the rectangle patches added
- """
- if coloredge is None:
- coloredgeup = colorup
- coloredgedown = colordown
- else:
- coloredgeup=coloredge
- coloredgedown=coloredge
- OFFSET = width / 2.0
- lines = []
- patches = []
- for q in quotes:
- if ochl:
- t, open, close, high, low = q[:5]
- else:
- t, open, high, low, close = q[:5]
- if close >= open:
- color = colorup
- lower = open
- height = close-open
- vline = Line2D(xdata=(t, t), ydata=(low, high), color=coloredgeup, linewidth=0.5, antialiased=True, zorder=0)
- else:
- color = colordown
- lower = close
- height = open-close
- vline = Line2D(xdata=(t, t), ydata=(low, high), color=coloredgedown, linewidth=0.5, antialiased=True, zorder=0)
- if coloredge is None:
- edgecolor = color
- rect = Rectangle(
- xy=(t - OFFSET, lower),
- width = width,
- height = height,
- facecolor = color,
- edgecolor = coloredge,
- zorder=1,
- )
- rect.set_alpha(alpha)
- lines.append(vline)
- patches.append(rect)
- ax.add_line(vline)
- ax.add_patch(rect)
- ax.autoscale_view()
- return lines, patches
- def candlestick(ax, quotes, width=0.2, colorup='k', colordown='r',
- alpha=1.0, coloredge=None):
- """
- Plot the time, open, close, high, low as a vertical line ranging
- from low to high. Use a rectangular bar to represent the
- open-close span. If close >= open, use colorup to color the bar,
- otherwise use colordown
- This function has been deprecated in 1.4 in favor of
- `candlestick_ochl`, which maintains the original argument
- order, or `candlestick_ohlc`, which uses the
- open-high-low-close order. This function will be removed in 1.5
- Parameters
- ----------
- ax : `Axes`
- an Axes instance to plot to
- quotes : sequence of (time, open, close, high, low, ...) sequences
- As long as the first 5 elements are these values,
- the record can be as long as you want (e.g., it may store volume).
- time must be in float days format - see date2num
- width : float
- fraction of a day for the rectangle width
- colorup : color
- the color of the rectangle where close >= open
- colordown : color
- the color of the rectangle where close < open
- alpha : float
- the rectangle alpha level
- coloregde : color (optional)
- the color of the edge. default is color of the candlebody
- Returns
- -------
- ret : tuple
- returns (lines, patches) where lines is a list of lines
- added and patches is a list of the rectangle patches added
- """
- warnings.warn(_warn_str.format(fun='candlestick'),
- mplDeprecation)
- return _candlestick(ax, quotes, width=width, colorup=colorup,
- colordown=colordown,
- alpha=alpha, ochl=True, coloredge=coloredge)
- def candlestick_ochl(ax, quotes, width=0.2, colorup='k', colordown='r',
- alpha=1.0, coloredge=None):
- """
- Plot the time, open, close, high, low as a vertical line ranging
- from low to high. Use a rectangular bar to represent the
- open-close span. If close >= open, use colorup to color the bar,
- otherwise use colordown
- Parameters
- ----------
- ax : `Axes`
- an Axes instance to plot to
- quotes : sequence of (time, open, close, high, low, ...) sequences
- As long as the first 5 elements are these values,
- the record can be as long as you want (e.g., it may store volume).
- time must be in float days format - see date2num
- width : float
- fraction of a day for the rectangle width
- colorup : color
- the color of the rectangle where close >= open
- colordown : color
- the color of the rectangle where close < open
- alpha : float
- the rectangle alpha level
- coloregde : color (optional)
- the color of the edge. default is color of the candlebody
- Returns
- -------
- ret : tuple
- returns (lines, patches) where lines is a list of lines
- added and patches is a list of the rectangle patches added
- """
- return _candlestick(ax, quotes, width=width, colorup=colorup,
- colordown=colordown,
- alpha=alpha, ochl=True, coloredge=coloredge)
- def candlestick_ohlc(ax, quotes, width=0.2, colorup='k', colordown='r',
- alpha=1.0, coloredge=None):
- """
- Plot the time, open, high, low, close as a vertical line ranging
- from low to high. Use a rectangular bar to represent the
- open-close span. If close >= open, use colorup to color the bar,
- otherwise use colordown
- Parameters
- ----------
- ax : `Axes`
- an Axes instance to plot to
- quotes : sequence of (time, open, high, low, close, ...) sequences
- As long as the first 5 elements are these values,
- the record can be as long as you want (e.g., it may store volume).
- time must be in float days format - see date2num
- width : float
- fraction of a day for the rectangle width
- colorup : color
- the color of the rectangle where close >= open
- colordown : color
- the color of the rectangle where close < open
- alpha : float
- the rectangle alpha level
- coloregde : color (optional)
- the color of the edge. default is color of the candlebody
- Returns
- -------
- ret : tuple
- returns (lines, patches) where lines is a list of lines
- added and patches is a list of the rectangle patches added
- """
- return _candlestick(ax, quotes, width=width, colorup=colorup,
- colordown=colordown,
- alpha=alpha, ochl=False, coloredge=coloredge)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement