Python Matplotlib如何调整烛台阴影颜色?

时间:2014-02-07 23:46:11

标签: python python-2.7 matplotlib finance

我正在关注youtube上的教程,用于创建烛台图表并遇到一个有趣的问题。本教程显示您可以通过直接更改matplotlib finance.py文件来编辑烛台线颜色。 finance.py文件中的原始代码如下所示:

lines = []
patches = []
for q in quotes:
    t, open, close, high, low = 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='k',
        linewidth=0.5,
        antialiased=True,
        )

注意vline部分。以下是调整后的代码:

lines = []
patches = []
for q in quotes:
    t, open, close, high, low = q[:5]

    if close>=open :
        color = colorup
        lower = open
        height = close-open
        vline = Line2D(
            xdata=(t, t), ydata=(low, high),
            color=colorup,
            linewidth=0.5,
            antialiased=True,
            )   
    else           :
        color = colordown
        lower = close
        height = open-close
        vline = Line2D(
            xdata=(t, t), ydata=(low, high),
            color=colordown,
            linewidth=0.5,
            antialiased=True,
            )

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

由于我无法理解的原因,阴影仍显示为黑色。我试过两种配置。

  1. Windows XP Python 2.7 Anaconda发行版Matplotlib 1.3
  2. Windows 7 Python 2.7 Python(xy)发行版Matplotlib 1.3
  3. 感谢任何帮助。感谢。

1 个答案:

答案 0 :(得分:0)

您是否在函数定义中定义了colorup和colordown?您还需要将def更改为以下内容:

  

def烛台(ax,quotes,width = 0.2,colorup =' k',colordown =' r',   阿尔法= 1.0):