如何用python画K线图

2023-05-16

第一步:导入相应的库
import tushare as ts
import matplotlib.pyplot as plt
import numpy as np

第二步:导入mpl_finance.py脚本文件

import mpl_finance as mpf

其中,mpl_finance.py脚本文件如下:

"""
A collection of functions for analyzing and plotting
financial data.   User contributions welcome!

"""
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

import numpy as np
from matplotlib import colors as mcolors
from matplotlib.collections import LineCollection, PolyCollection
from matplotlib.lines import TICKLEFT, TICKRIGHT, Line2D
from matplotlib.patches import Rectangle
from matplotlib.transforms import Affine2D

from six.moves import xrange, zip


def plot_day_summary_oclh(ax, quotes, ticksize=3,
                          colorup='k', colordown='r'):
    """Plots day summary

        Represent the time, open, close, high, low as a vertical line
        ranging from low to high.  The left tick is the open and the right
        tick is the close.



    Parameters
    ----------
    ax : `Axes`
        an `Axes` instance to plot to
    quotes : sequence of (time, open, close, high, low, ...) sequences
        data to plot.  time must be in float date format - see date2num
    ticksize : int
        open/close tick marker in points
    colorup : color
        the color of the lines where close >= open
    colordown : color
        the color of the lines where close <  open

    Returns
    -------
    lines : list
        list of tuples of the lines added (one tuple per quote)
    """
    return _plot_day_summary(ax, quotes, ticksize=ticksize,
                             colorup=colorup, colordown=colordown,
                             ochl=True)


def plot_day_summary_ohlc(ax, quotes, ticksize=3,
                          colorup='k', colordown='r'):
    """Plots day summary

        Represent the time, open, high, low, close as a vertical line
        ranging from low to high.  The left tick is the open and the right
        tick is the close.



    Parameters
    ----------
    ax : `Axes`
        an `Axes` instance to plot to
    quotes : sequence of (time, open, high, low, close, ...) sequences
        data to plot.  time must be in float date format - see date2num
    ticksize : int
        open/close tick marker in points
    colorup : color
        the color of the lines where close >= open
    colordown : color
        the color of the lines where close <  open

    Returns
    -------
    lines : list
        list of tuples of the lines added (one tuple per quote)
    """
    return _plot_day_summary(ax, quotes, ticksize=ticksize,
                             colorup=colorup, colordown=colordown,
                             ochl=False)


def _plot_day_summary(ax, quotes, ticksize=3,
                      colorup='k', colordown='r',
                      ochl=True):
    """Plots day summary


        Represent the time, open, high, low, close as a vertical line
        ranging from low to high.  The left tick is the open and the right
        tick is the close.



    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`
    ticksize : int
        open/close tick marker in points
    colorup : color
        the color of the lines where close >= open
    colordown : color
        the color of the lines where close <  open
    ochl: bool
        argument to select between ochl and ohlc ordering of quotes

    Returns
    -------
    lines : list
        list of tuples of the lines added (one tuple per quote)
    """
    # unfortunately this has a different return type than plot_day_summary2_*
    lines = []
    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
        else:
            color = colordown

        vline = Line2D(xdata=(t, t), ydata=(low, high),
                       color=color,
                       antialiased=False,   # no need to antialias vert lines
                       )

        oline = Line2D(xdata=(t, t), ydata=(open, open),
                       color=color,
                       antialiased=False,
                       marker=TICKLEFT,
                       markersize=ticksize,
                       )

        cline = Line2D(xdata=(t, t), ydata=(close, close),
                       color=color,
                       antialiased=False,
                       markersize=ticksize,
                       marker=TICKRIGHT)

        lines.extend((vline, oline, cline))
        ax.add_line(vline)
        ax.add_line(oline)
        ax.add_line(cline)

    ax.autoscale_view()

    return lines


def candlestick_ochl(ax, quotes, width=0.2, colorup='k', colordown='r',
                     alpha=1.0):
    """
    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

    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)


def candlestick_ohlc(ax, quotes, width=0.2, colorup='k', colordown='r',
                     alpha=1.0):
    """
    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

    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)


def _candlestick(ax, quotes, width=0.2, colorup='k', colordown='r',
                 alpha=1.0, ochl=True):
    """
    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

    Returns
    -------
    ret : tuple
        returns (lines, patches) where lines is a list of lines
        added and patches is a list of the rectangle patches added

    """

    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
        else:
            color = colordown
            lower = close
            height = open - close

        vline = Line2D(
            xdata=(t, t), ydata=(low, high),
            color=color,
            linewidth=0.5,
            antialiased=True,
        )

        rect = Rectangle(
            xy=(t - OFFSET, lower),
            width=width,
            height=height,
            facecolor=color,
            edgecolor=color,
        )
        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 _check_input(opens, closes, highs, lows, miss=-1):
    """Checks that *opens*, *highs*, *lows* and *closes* have the same length.
    NOTE: this code assumes if any value open, high, low, close is
    missing (*-1*) they all are missing

    Parameters
    ----------
    ax : `Axes`
        an Axes instance to plot to
    opens : sequence
        sequence of opening values
    highs : sequence
        sequence of high values
    lows : sequence
        sequence of low values
    closes : sequence
        sequence of closing values
    miss : int
        identifier of the missing data

    Raises
    ------
    ValueError
        if the input sequences don't have the same length
    """

    def _missing(sequence, miss=-1):
        """Returns the index in *sequence* of the missing data, identified by
        *miss*

        Parameters
        ----------
        sequence :
            sequence to evaluate
        miss :
            identifier of the missing data

        Returns
        -------
        where_miss: numpy.ndarray
            indices of the missing data
        """
        return np.where(np.array(sequence) == miss)[0]

    same_length = len(opens) == len(highs) == len(lows) == len(closes)
    _missopens = _missing(opens)
    same_missing = ((_missopens == _missing(highs)).all() and
                    (_missopens == _missing(lows)).all() and
                    (_missopens == _missing(closes)).all())

    if not (same_length and same_missing):
        msg = ("*opens*, *highs*, *lows* and *closes* must have the same"
               " length. NOTE: this code assumes if any value open, high,"
               " low, close is missing (*-1*) they all must be missing.")
        raise ValueError(msg)


def plot_day_summary2_ochl(ax, opens, closes, highs, lows, ticksize=4,
                           colorup='k', colordown='r'):
    """Represent the time, open, close, high, low,  as a vertical line
    ranging from low to high.  The left tick is the open and the right
    tick is the close.

    Parameters
    ----------
    ax : `Axes`
        an Axes instance to plot to
    opens : sequence
        sequence of opening values
    closes : sequence
        sequence of closing values
    highs : sequence
        sequence of high values
    lows : sequence
        sequence of low values
    ticksize : int
        size of open and close ticks in points
    colorup : color
        the color of the lines where close >= open
    colordown : color
         the color of the lines where close <  open

    Returns
    -------
    ret : list
        a list of lines added to the axes
    """

    return plot_day_summary2_ohlc(ax, opens, highs, lows, closes, ticksize,
                                  colorup, colordown)


def plot_day_summary2_ohlc(ax, opens, highs, lows, closes, ticksize=4,
                           colorup='k', colordown='r'):
    """Represent the time, open, high, low, close as a vertical line
    ranging from low to high.  The left tick is the open and the right
    tick is the close.
    *opens*, *highs*, *lows* and *closes* must have the same length.
    NOTE: this code assumes if any value open, high, low, close is
    missing (*-1*) they all are missing

    Parameters
    ----------
    ax : `Axes`
        an Axes instance to plot to
    opens : sequence
        sequence of opening values
    highs : sequence
        sequence of high values
    lows : sequence
        sequence of low values
    closes : sequence
        sequence of closing values
    ticksize : int
        size of open and close ticks in points
    colorup : color
        the color of the lines where close >= open
    colordown : color
         the color of the lines where close <  open

    Returns
    -------
    ret : list
        a list of lines added to the axes
    """

    _check_input(opens, highs, lows, closes)

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

    # the ticks will be from ticksize to 0 in points at the origin and
    # we'll translate these to the i, close location
    openSegments = [((-ticksize, 0), (0, 0))]

    # the ticks will be from 0 to ticksize in points at the origin and
    # we'll translate these to the i, close location
    closeSegments = [((0, 0), (ticksize, 0))]

    offsetsOpen = [(i, open) for i, open in
                   zip(xrange(len(opens)), opens) if open != -1]

    offsetsClose = [(i, close) for i, close in
                    zip(xrange(len(closes)), closes) if close != -1]

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

    tickTransform = Affine2D().scale(scale, 0.0)

    colorup = mcolors.to_rgba(colorup)
    colordown = mcolors.to_rgba(colordown)
    colord = {True: colorup, False: colordown}
    colors = [colord[open < close] for open, close in
              zip(opens, closes) if open != -1 and close != -1]

    useAA = 0,   # use tuple here
    lw = 1,      # and here
    rangeCollection = LineCollection(rangeSegments,
                                     colors=colors,
                                     linewidths=lw,
                                     antialiaseds=useAA,
                                     )

    openCollection = LineCollection(openSegments,
                                    colors=colors,
                                    antialiaseds=useAA,
                                    linewidths=lw,
                                    offsets=offsetsOpen,
                                    transOffset=ax.transData,
                                    )
    openCollection.set_transform(tickTransform)

    closeCollection = LineCollection(closeSegments,
                                     colors=colors,
                                     antialiaseds=useAA,
                                     linewidths=lw,
                                     offsets=offsetsClose,
                                     transOffset=ax.transData,
                                     )
    closeCollection.set_transform(tickTransform)

    minpy, maxx = (0, len(rangeSegments))
    miny = min([low for low in lows if low != -1])
    maxy = max([high for high in highs if high != -1])
    corners = (minpy, miny), (maxx, maxy)
    ax.update_datalim(corners)
    ax.autoscale_view()

    # add these last
    ax.add_collection(rangeCollection)
    ax.add_collection(openCollection)
    ax.add_collection(closeCollection)
    return rangeCollection, openCollection, closeCollection


def candlestick2_ochl(ax, opens, closes, highs, lows, width=4,
                      colorup='k', colordown='r',
                      alpha=0.75):
    """Represent the open, close as a bar line and high low range as a
    vertical line.

    Preserves the original argument order.


    Parameters
    ----------
    ax : `Axes`
        an Axes instance to plot to
    opens : sequence
        sequence of opening values
    closes : sequence
        sequence of closing values
    highs : sequence
        sequence of high values
    lows : sequence
        sequence of low values
    width : int
        size of open and close ticks in points
    colorup : color
        the color of the lines where close >= open
    colordown : color
        the color of the lines where close <  open
    alpha : float
        bar transparency

    Returns
    -------
    ret : tuple
        (lineCollection, barCollection)
    """

    return candlestick2_ohlc(ax, opens, highs, lows, closes, width=width,
                             colorup=colorup, colordown=colordown,
                             alpha=alpha)


def candlestick2_ohlc(ax, opens, highs, lows, closes, width=4,
                      colorup='k', colordown='r',
                      alpha=0.75):
    """Represent the open, close as a bar line and high low range as a
    vertical line.

    NOTE: this code assumes if any value open, low, high, close is
    missing they all are missing


    Parameters
    ----------
    ax : `Axes`
        an Axes instance to plot to
    opens : sequence
        sequence of opening values
    highs : sequence
        sequence of high values
    lows : sequence
        sequence of low values
    closes : sequence
        sequence of closing values
    width : int
        size of open and close ticks in points
    colorup : color
        the color of the lines where close >= open
    colordown : color
        the color of the lines where close <  open
    alpha : float
        bar transparency

    Returns
    -------
    ret : tuple
        (lineCollection, barCollection)
    """

    _check_input(opens, highs, lows, closes)

    delta = width / 2.
    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]

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

    colorup = mcolors.to_rgba(colorup, alpha)
    colordown = mcolors.to_rgba(colordown, alpha)
    colord = {True: colorup, False: colordown}
    colors = [colord[open < close]
              for open, close in zip(opens, closes)
              if open != -1 and close != -1]

    useAA = 0,  # use tuple here
    lw = 0.5,   # and here
    rangeCollection = LineCollection(rangeSegments,
                                     colors=colors,
                                     linewidths=lw,
                                     antialiaseds=useAA,
                                     )

    barCollection = PolyCollection(barVerts,
                                   facecolors=colors,
                                   edgecolors=colors,
                                   antialiaseds=useAA,
                                   linewidths=lw,
                                   )

    minx, maxx = 0, len(rangeSegments)
    miny = min([low for low in lows if low != -1])
    maxy = max([high for high in highs if high != -1])

    corners = (minx, miny), (maxx, maxy)
    ax.update_datalim(corners)
    ax.autoscale_view()

    # add these last
    ax.add_collection(rangeCollection)
    ax.add_collection(barCollection)
    return rangeCollection, barCollection


def volume_overlay(ax, opens, closes, volumes,
                   colorup='k', colordown='r',
                   width=4, alpha=1.0):
    """Add a volume overlay to the current axes.  The opens and closes
    are used to determine the color of the bar.  -1 is missing.  If a
    value is missing on one it must be missing on all

    Parameters
    ----------
    ax : `Axes`
        an Axes instance to plot to
    opens : sequence
        a sequence of opens
    closes : sequence
        a sequence of closes
    volumes : sequence
        a sequence of volumes
    width : int
        the bar width in points
    colorup : color
        the color of the lines where close >= open
    colordown : color
        the color of the lines where close <  open
    alpha : float
        bar transparency

    Returns
    -------
    ret : `barCollection`
        The `barrCollection` added to the axes

    """

    colorup = mcolors.to_rgba(colorup, alpha)
    colordown = mcolors.to_rgba(colordown, alpha)
    colord = {True: colorup, False: colordown}
    colors = [colord[open < close]
              for open, close in zip(opens, closes)
              if open != -1 and close != -1]

    delta = width / 2.
    bars = [((i - delta, 0), (i - delta, v), (i + delta, v), (i + delta, 0))
            for i, v in enumerate(volumes)
            if v != -1]

    barCollection = PolyCollection(bars,
                                   facecolors=colors,
                                   edgecolors=((0, 0, 0, 1), ),
                                   antialiaseds=(0,),
                                   linewidths=(0.5,),
                                   )

    ax.add_collection(barCollection)
    corners = (0, 0), (len(bars), max(volumes))
    ax.update_datalim(corners)
    ax.autoscale_view()

    # add these last
    return barCollection


def volume_overlay2(ax, closes, volumes,
                    colorup='k', colordown='r',
                    width=4, alpha=1.0):
    """
    Add a volume overlay to the current axes.  The closes are used to
    determine the color of the bar.  -1 is missing.  If a value is
    missing on one it must be missing on all

    nb: first point is not displayed - it is used only for choosing the
    right color


    Parameters
    ----------
    ax : `Axes`
        an Axes instance to plot to
    closes : sequence
        a sequence of closes
    volumes : sequence
        a sequence of volumes
    width : int
        the bar width in points
    colorup : color
        the color of the lines where close >= open
    colordown : color
        the color of the lines where close <  open
    alpha : float
        bar transparency

    Returns
    -------
    ret : `barCollection`
        The `barrCollection` added to the axes

    """

    return volume_overlay(ax, closes[:-1], closes[1:], volumes[1:],
                          colorup, colordown, width, alpha)


def volume_overlay3(ax, quotes,
                    colorup='k', colordown='r',
                    width=4, alpha=1.0):
    """Add a volume overlay to the current axes.  quotes is a list of (d,
    open, high, low, close, volume) and close-open is used to
    determine the color of the bar

    Parameters
    ----------
    ax : `Axes`
        an Axes instance to plot to
    quotes : sequence of (time, open, high, low, close, ...) sequences
        data to plot.  time must be in float date format - see date2num
    width : int
        the bar width in points
    colorup : color
        the color of the lines where close1 >= close0
    colordown : color
        the color of the lines where close1 <  close0
    alpha : float
         bar transparency

    Returns
    -------
    ret : `barCollection`
        The `barrCollection` added to the axes


    """

    colorup = mcolors.to_rgba(colorup, alpha)
    colordown = mcolors.to_rgba(colordown, alpha)
    colord = {True: colorup, False: colordown}

    dates, opens, highs, lows, closes, volumes = list(zip(*quotes))
    colors = [colord[close1 >= close0]
              for close0, close1 in zip(closes[:-1], closes[1:])
              if close0 != -1 and close1 != -1]
    colors.insert(0, colord[closes[0] >= opens[0]])

    right = width / 2.0
    left = -width / 2.0

    bars = [((left, 0), (left, volume), (right, volume), (right, 0))
            for d, open, high, low, close, volume in quotes]

    sx = ax.figure.dpi * (1.0 / 72.0)  # scale for points
    sy = ax.bbox.height / ax.viewLim.height

    barTransform = Affine2D().scale(sx, sy)

    dates = [d for d, open, high, low, close, volume in quotes]
    offsetsBars = [(d, 0) for d in dates]

    useAA = 0,  # use tuple here
    lw = 0.5,   # and here
    barCollection = PolyCollection(bars,
                                   facecolors=colors,
                                   edgecolors=((0, 0, 0, 1),),
                                   antialiaseds=useAA,
                                   linewidths=lw,
                                   offsets=offsetsBars,
                                   transOffset=ax.transData,
                                   )
    barCollection.set_transform(barTransform)

    minpy, maxx = (min(dates), max(dates))
    miny = 0
    maxy = max([volume for d, open, high, low, close, volume in quotes])
    corners = (minpy, miny), (maxx, maxy)
    ax.update_datalim(corners)
    # print 'datalim', ax.dataLim.bounds
    # print 'viewlim', ax.viewLim.bounds

    ax.add_collection(barCollection)
    ax.autoscale_view()

    return barCollection


def index_bar(ax, vals,
              facecolor='b', edgecolor='l',
              width=4, alpha=1.0, ):
    """Add a bar collection graph with height vals (-1 is missing).

    Parameters
    ----------
    ax : `Axes`
        an Axes instance to plot to
    vals : sequence
        a sequence of values
    facecolor : color
        the color of the bar face
    edgecolor : color
        the color of the bar edges
    width : int
        the bar width in points
    alpha : float
       bar transparency

    Returns
    -------
    ret : `barCollection`
        The `barrCollection` added to the axes

    """

    facecolors = (mcolors.to_rgba(facecolor, alpha),)
    edgecolors = (mcolors.to_rgba(edgecolor, alpha),)

    right = width / 2.0
    left = -width / 2.0

    bars = [((left, 0), (left, v), (right, v), (right, 0))
            for v in vals if v != -1]

    sx = ax.figure.dpi * (1.0 / 72.0)  # scale for points
    sy = ax.bbox.height / ax.viewLim.height

    barTransform = Affine2D().scale(sx, sy)

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

    barCollection = PolyCollection(bars,
                                   facecolors=facecolors,
                                   edgecolors=edgecolors,
                                   antialiaseds=(0,),
                                   linewidths=(0.5,),
                                   offsets=offsetsBars,
                                   transOffset=ax.transData,
                                   )
    barCollection.set_transform(barTransform)

    minpy, maxx = (0, len(offsetsBars))
    miny = 0
    maxy = max([v for v in vals if v != -1])
    corners = (minpy, miny), (maxx, maxy)
    ax.update_datalim(corners)
    ax.autoscale_view()

    # add these last
    ax.add_collection(barCollection)
    return barCollection

第三步:运行以下代码:

import tushare as ts
import matplotlib.pyplot as plt
import mpl_finance as mpf
import numpy as np
data = ts.get_k_data('600519', ktype='D', autype='qfq', start='2017-09-17', end='')
prices = data[['open', 'high', 'low', 'close']]
dates = data['date']
candleData = np.column_stack([list(range(len(dates))), prices])
fig = plt.figure(figsize=(10, 6))
ax = fig.add_axes([0.1, 0.3, 0.8, 0.6])
mpf.candlestick_ohlc(ax, candleData, width=0.5, colorup='r', colordown='b')
plt.show()

第四步:运行结果




本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何用python画K线图 的相关文章

  • 关于ros安装过程设置密钥不成功解决方案

    问题 xff1a 设置密钥语句 xff1a curl s https raw githubusercontent com ros rosdistro master ros asc sudo apt key add 出现错误 xff1a gp
  • CmakeLists所遇命令用法总结

    1 option命令 xff1a 形式 xff1a option lt variable gt 34 lt help text gt 34 value 简介 xff1a cmake中option起到编译开关的作用 xff0c CMakeLi
  • OpenCV——图像二值化

    OpenCV图像二值化提供了两种函数 threshold double threshold InputArray src OutputArray dst double thresh double maxval int type src xf
  • ubuntu18.04运行ORBSLAM2踩坑记录

    坑1 xff1a error 39 usleep 39 was not declared in this scope usleep 3000 解决办法 xff1a 在对应报错文件中添加头文件 xff1a include lt unistd
  • 单目相机标定

    1 下载usb cam安装包 xff0c 放置到 catkin ws src目录下 cd catkin ws src git clone https github com bosch ros pkg usb cam git usb cam
  • ubuntu18.04安装google浏览器

    sudo wget http www linuxidc com files repo google chrome list P etc apt sources list d wget q O https dl google com linu
  • ubuntu18.04安装opencv3.2.0

    1 下载所需安装包 opencv 3 2 0下载地址 xff1a opencv 3 2 0 opencv contrib 3 2 0下载地址 xff1a opencv contrib 3 2 0 2 安装所需依赖 sudo apt get
  • vscode调试orbslam2配置过程

    1 c cpp properties json 34 configurations 34 34 name 34 34 Linux 34 34 includePath 34 34 workspaceFolder 34 34 usr inclu
  • 喜茶皇茶茶叶带您走上致富之路

    我国是茶文化的发源地 xff0c 尤其是南方各类品种的茶层出不穷 xff0c 茶韵茶香引人入胜 消费者生活水平大幅提高 xff0c 饮茶几乎已经成为一种时尚 xff0c 皇茶 在市场上受到大家的认可与喜爱 xff0c 短短时间内迅速发展壮大
  • UCOSII pdf 电子书籍

    https pan baidu com share init surl 61 RrZKnhvCuC 3qCOT0bi1Gg 提取码 xff1a 4a0f
  • 变频器的逆变、变频原理

    变频器的逆变 变频原理 YJZhang 从事制造业质量管理 xff0c 做过PCBA 线束 电话机 变频器行业 90 人赞同了该文章 变频器将直流电转变为交流电的这个过程叫 逆变 xff08 inverting 先讲逆变过程 xff0c 分
  • 8086中断系统——《x86汇编语言:从实模式到保护模式》读书笔记04

    80X86中断系统 能够处理256个中断 用中断向量号0 xff5e 255区别 可屏蔽中断还需要借助专用中断控制器Intel 8259A实现优先权管理 1 中断的分类 中断可以分为内部中断和外部中断 xff08 1 xff09 内部中断
  • 任务切换的方法——《x86汇编语言:从实模式到保护模式》读书笔记37

    任务切换的方法 x86汇编语言 xff1a 从实模式到保护模式 读书笔记37 1 中断门和陷阱门 在实模式下 xff0c 内存最低端的1M是中断向量表 xff0c 保存着256个中断处理过程的段地址和偏移 当中断发生时 xff0c 处理器把
  • 不用 H5,闲鱼 Flutter 如何玩转小游戏?

    阿里妹导读 xff1a 最近APP游戏化成为了一个新的风口 xff0c 把在游戏中一些好玩的 能吸引用户的娱乐方式或场景应用在应用当中 xff0c 以达到增加用户粘性 xff0c 提升DAU的效果 xff0c 成本较低 同时在一些需要对用户
  • 【Invalid bound statement (not found)的解决方法】

    前言 xff1a 先说下我自己 xff0c 最开始我是可以的 xff0c 结果我去改了下mapper接口里方法的参数类型 xff0c 突然就报Invalid bound statement not found 这个错误 xff0c 我在网上
  • FreeRTOS学习(四) 列表的插入和删除

    声明及感谢 跟随正点原子资料学习 在此作为学习的记录和总结 环境 keil stm32f103 首先定义列表 xff0c 以及列表项 List t TestList 列表 ListItem t ListItem1 列表项1 ListItem
  • FreeRTOS学习(六) 时间片调度

    声明及感谢 跟随正点原子资料学习 在此作为学习的记录和总结 环境 keil stm32f103 对于FreeRTOS 允许同等任务优先级存在 那么对于多个同等优先级的任务运行 情况的是如何 FreeRTOS 的机制就是对于同等优先级任务来说
  • FreeRTOS学习(十) 信号量

    声明及感谢 跟随正点原子资料学习 在此作为学习的记录和总结 环境 keil stm32f103 二值信号量 二值信号量 通常用于互斥访问 或同步 大多数用于同步 任务与任务 或 任务 与中断的同步 和队列一样 信号量API函数允许设置一个阻
  • Arduino 操控 12v 电压控制电磁铁 (线性振动马达?

    在此记录一下制作过程 xff0c 以作日后参考 效果 xff1a 线性震动马达 xff1f 大概思路 xff1a 通过L298N xff0c 用外接12v电源给电磁铁进行12v供电 xff0c 给arduino进行5v供电 一个电磁铁的供电
  • Dijkstra算法详解

    1 dijkstra算法简介 Dijkstra算法是由E W Dijkstra于1959年提出 xff0c 又叫迪杰斯特拉算法 xff0c 它应用了贪心算法模式 xff0c 是目前公认的最好的求解最短路径的方法 算法解决的是有向图中单个源点

随机推荐

  • C++建立动态二维数组

    C 43 43 建立动态二维数组主要有两种方法 xff1a 1 使用数组指针 xff0c 分配一个指针数组 xff0c 将其首地址保存在b中 xff0c 然后再为指针数组的每个元素分配一个数组 int b 61 new int row 分配
  • 理解负载均衡

    什么是平均负载 xff1f 单位时间内 xff0c 系统处于可运行状态和不可中断状态的平均进程数 xff0c 也就是平均活跃进程数 xff0c 它和CPU使用率并没有直接关系 所谓可运行状态的进程 xff0c 是指正在使用CPU或者等待CP
  • 理解CPU使用率和CPU上下文切换

    1 CPU使用率 1 1 CPU使用率查看 当发现服务或机器卡的时候 xff0c 我们都是先通过top命令查看服务器CPU使用率 默认每3秒刷新一次 top top 18 10 58 up 1216 days 7 38 4 users lo
  • 自动驾驶概述

    1 自动化能力定义 对自动驾驶能力有多个定义标准 xff0c 比较常用的是SAE International关于自动化层级的定义 具体是 L0 驾驶员完全掌控车辆 L1 自动系统有时能够辅助驾驶员完成某些驾驶任务 L2 自动系统能够完成某些
  • 2014百度校招笔试题之动态链接库&静态链接库详解

    1 什么是静态连接库 xff0c 什么是动态链接库 静态链接库用通俗的话讲 静态库就是将代码编译到一个二进制文件下 通常扩展名为 LIB 然后客户端调用程序 只需要包含相关的 h文件及LIB库文件一起链接到exe文件中 可执行程序发布后 不
  • @武汉人民,请收好这份名单

    1月27日 xff0c 武汉本地众多商户联合阿里巴巴旗下饿了么口碑 盒马 飞猪等业务 xff0c 从衣食住行各个角度 xff0c 为武汉一线医护人员提供安全 高品质的餐品及生活配套服务 首批100家餐厅已准备就绪 其中麦当劳 华莱士 大米先
  • java遍历泛型的方法

    一 List遍历 Java中List遍历有三种方法来遍历泛型 xff0c 主要为 xff1a 1 for循环遍历 2 iterator遍历 3 foreach遍历 package com gmail lsgjzhuwei import ja
  • java web文件下载功能实现

    需求 xff1a 实现一个具有文件下载功能的网页 xff0c 主要下载压缩包和图片 两种实现方法 xff1a 一 xff1a 通过超链接实现下载 在HTML网页中 xff0c 通过超链接链接到要下载的文件的地址 lt DOCTYPE htm
  • java创建线程的三种方式及其对比

    Java中创建线程主要有三种方式 xff1a 一 继承Thread类创建线程类 xff08 1 xff09 定义Thread类的子类 xff0c 并重写该类的run方法 xff0c 该run方法的方法体就代表了线程要完成的任务 因此把run
  • 'hibernate.dialect' must be set when no Connection available

    今天碰到的这个问题 xff0c 很无厘头 xff0c 网上搜索了很多 xff0c 都不靠谱 xff0c 还是靠自己 解决方法是在hibernate cfg xml中添加 lt property name 61 34 dialect 34 g
  • javascript动态插入html元素

    主要有是两种方案 xff1a 1 使用DOM span class hljs comment 使用createElement创建元素 span span class hljs keyword var span dialog 61 docum
  • python中switch语句用法

    python中是没用switch语句的 xff0c 这应该是体现python大道至简的思想 xff0c python中一般多用字典来代替switch来实现 coding utf 8 from future import division d
  • ROS的 sudo rosdep init 的报错终极解决方案

    ROS的 sudo rosdep init 的报错解决方案 安装ROS时sudo rosdep init指令报错 xff1a ERROR span class token operator span cannot download span
  • 图解Word2vec

    作者 xff1a 龙心尘 时间 xff1a 2019年4月 出处 xff1a https blog csdn net longxinchen ml article details 89077048 审校 xff1a 龙心尘 作者 xff1a
  • api 功能与实现的些许感想

    api 功能与实现 对于 api 功能的了解 xff0c 通过学习源码的实现便能做到 反之 xff0c 通过研究源码 xff0c 也能对api 功能有所了解 api 功能与实现的这种相互联系意味着我们不应该将 api 的功能与实现切割开 x
  • 浅谈驱动开发

    驱动开发没那么高大上 驱动开发在很多人眼中都是一项极具挑战性的任务 xff0c 可当你真正去开发一个驱动时 xff0c 你也许会发现它并没有看上去那样困难 xff0c 可对大多数人而言驱动开发是八竿子打不着的话题 xff0c 故而更增强了驱
  • 新冠病毒破解有了巨大突破,达摩院做了什么?

    阿里巴巴达摩院正在用AI算法抗击新型冠状病毒肺炎疫情 2月1日 xff0c 浙江省疾控中心上线自动化的全基因组检测分析平台 利用阿里达摩院研发的AI算法 xff0c 可将原来数小时的疑似病例基因分析缩短至半小时 xff0c 大幅缩短确诊时间
  • 免费AI训练平台“九天·毕昇”

    AI 训练平台 九天 毕昇 xff0c https jtedu cmri cn register token 61 ZDZiZDhmMDQtNmJiZC00M2ZkLWI3NjItMTU1MzNhZWRkNTYz 可以免费获取50小时计算资
  • 鸢尾花数据集使用

    from sklearn datasets import load iris 加载数据集iris 61 load iris print iris keys 数据的条数和维数n samples n features 61 iris data
  • 如何用python画K线图

    第一步 xff1a 导入相应的库 import tushare as ts import matplotlib pyplot as plt import numpy as np 第二步 xff1a 导入mpl finance py脚本文件