首页 > 解决方案 > 没有名为“matplotlib.finance”的模块,已弃用,且 mpl_finance 也未维护

问题描述

我需要在图表上绘制一些带有额外线条和各种图形的烛台图表,但我发现它matplotlib.finance已被弃用。替换为mpl_finance,但这也没有维护。

如今,一个诚实的新生 python 开发人员应该使用什么来绘制烛台?有任何想法吗?

我将用于此的代码将类似于:

将 matplotlib.pyplot 导入为 plt

from matplotlib.dates import DateFormatter, WeekdayLocator,\
    DayLocator, MONDAY
from matplotlib.finance import candlestick_ohlc

    mondays = WeekdayLocator(MONDAY)
    alldays = DayLocator()              # minor ticks on the days
    weekFormatter = DateFormatter('%b %d')  # e.g., Jan 12
    dayFormatter = DateFormatter('%d')      # e.g., 12

    fig, ax = plt.subplots()
    fig.subplots_adjust(bottom=0.2)
    ax.xaxis.set_major_locator(mondays)
    ax.xaxis.set_minor_locator(alldays)
    ax.xaxis.set_major_formatter(weekFormatter)
    # ax.xaxis.set_minor_formatter(dayFormatter)

    #plot_day_summary(ax, quotes, ticksize=3)
    candlestick_ohlc(ax, candles, width=0.6)

    ax.xaxis_date()
    ax.autoscale_view()
    plt.setp(plt.gca().get_xticklabels(),
             rotation=45, horizontalalignment='right')

标签: pythonmatplotlib

解决方案


您可以mpl_finance不受限制地使用。可在github.com/matplotlib/mpl_finance 获得。请参阅此处了解如何安装它。

“未维护”只是意味着如果您发现其中的错误,没有人会为您修复它。


推荐阅读