matplotlib candlestick_ohlc 函数上奇怪的随机宽度
Weird random width on matplotlib candlestick_ohlc function
我正在使用 matplotlib 中的 candlestick_ohlc
绘制短烛条形态,我将 width
的设置设置为 0.01
。并且总是画 6 支蜡烛。
大多数情况下,条形图看起来都符合预期,但每张图片中有五分之一(或多或少)的宽度更大,会破坏图形。
这是我如何使用我的函数的示例:
candlestick_ohlc(ax1, candles, width=0.01,colorup='green', colordown='red')
以及正在处理的数据示例:
[[7.37151000e+05 1.30622000e+00 1.30658000e+00 1.30597000e+00 1.30610000e+00]
[7.37151010e+05 1.30609000e+00 1.30619000e+00 1.30500000e+00 1.30595000e+00]
[7.37151021e+05 1.30594000e+00 1.30621000e+00 1.30575000e+00 1.30602000e+00]
[7.37151031e+05 1.30603000e+00 1.30644000e+00 1.30603000e+00 1.30632000e+00]
[7.37151042e+05 1.30633000e+00 1.30648000e+00 1.30622000e+00 1.30648000e+00]
[7.37151052e+05 1.30644000e+00 1.30661000e+00 1.30551000e+00 1.30553000e+00]]
[[7.37151010e+05 1.30609000e+00 1.30619000e+00 1.30500000e+00 1.30595000e+00]
[7.37151021e+05 1.30594000e+00 1.30621000e+00 1.30575000e+00 1.30602000e+00]
[7.37151031e+05 1.30603000e+00 1.30644000e+00 1.30603000e+00 1.30632000e+00]
[7.37151042e+05 1.30633000e+00 1.30648000e+00 1.30622000e+00 1.30648000e+00]
[7.37151052e+05 1.30644000e+00 1.30661000e+00 1.30551000e+00 1.30553000e+00]
[7.37151062e+05 1.30553000e+00 1.30590000e+00 1.30529000e+00 1.30573000e+00]]
[[7.37151060e+05 1.30561000e+00 1.30561000e+00 1.30549000e+00 1.30551000e+00]
[7.37151060e+05 1.30550000e+00 1.30568000e+00 1.30550000e+00 1.30568000e+00]
[7.37151061e+05 1.30565000e+00 1.30580000e+00 1.30562000e+00 1.30580000e+00]
[7.37151062e+05 1.30580000e+00 1.30583000e+00 1.30578000e+00 1.30578000e+00]
[7.37151062e+05 1.30579000e+00 1.30590000e+00 1.30566000e+00 1.30573000e+00]
[7.37151063e+05 1.30573000e+00 1.30574000e+00 1.30550000e+00 1.30561000e+00]]
正如 ImportanceOfBeingErnest 所说 "In those cases where it doesn't work out, you need to further reduce the width. More precisely, the width should never be larger than the difference between two successive x data points."
也就是说,有一个新版本的 matplotlib finance 可以自动为您处理这个问题。您可以在此处找到新版本和文档:
https://pypi.org/project/mplfinance/
安装:pip install --upgrade mplfinance
注意:软件包名称不再包含破折号或下划线:
现在是 mplfinance(不是 mpl-finance,也不是 mpl_finance)
我正在使用 matplotlib 中的 candlestick_ohlc
绘制短烛条形态,我将 width
的设置设置为 0.01
。并且总是画 6 支蜡烛。
大多数情况下,条形图看起来都符合预期,但每张图片中有五分之一(或多或少)的宽度更大,会破坏图形。
这是我如何使用我的函数的示例:
candlestick_ohlc(ax1, candles, width=0.01,colorup='green', colordown='red')
以及正在处理的数据示例:
[[7.37151000e+05 1.30622000e+00 1.30658000e+00 1.30597000e+00 1.30610000e+00]
[7.37151010e+05 1.30609000e+00 1.30619000e+00 1.30500000e+00 1.30595000e+00]
[7.37151021e+05 1.30594000e+00 1.30621000e+00 1.30575000e+00 1.30602000e+00]
[7.37151031e+05 1.30603000e+00 1.30644000e+00 1.30603000e+00 1.30632000e+00]
[7.37151042e+05 1.30633000e+00 1.30648000e+00 1.30622000e+00 1.30648000e+00]
[7.37151052e+05 1.30644000e+00 1.30661000e+00 1.30551000e+00 1.30553000e+00]]
[[7.37151010e+05 1.30609000e+00 1.30619000e+00 1.30500000e+00 1.30595000e+00]
[7.37151021e+05 1.30594000e+00 1.30621000e+00 1.30575000e+00 1.30602000e+00]
[7.37151031e+05 1.30603000e+00 1.30644000e+00 1.30603000e+00 1.30632000e+00]
[7.37151042e+05 1.30633000e+00 1.30648000e+00 1.30622000e+00 1.30648000e+00]
[7.37151052e+05 1.30644000e+00 1.30661000e+00 1.30551000e+00 1.30553000e+00]
[7.37151062e+05 1.30553000e+00 1.30590000e+00 1.30529000e+00 1.30573000e+00]]
[[7.37151060e+05 1.30561000e+00 1.30561000e+00 1.30549000e+00 1.30551000e+00]
[7.37151060e+05 1.30550000e+00 1.30568000e+00 1.30550000e+00 1.30568000e+00]
[7.37151061e+05 1.30565000e+00 1.30580000e+00 1.30562000e+00 1.30580000e+00]
[7.37151062e+05 1.30580000e+00 1.30583000e+00 1.30578000e+00 1.30578000e+00]
[7.37151062e+05 1.30579000e+00 1.30590000e+00 1.30566000e+00 1.30573000e+00]
[7.37151063e+05 1.30573000e+00 1.30574000e+00 1.30550000e+00 1.30561000e+00]]
正如 ImportanceOfBeingErnest 所说 "In those cases where it doesn't work out, you need to further reduce the width. More precisely, the width should never be larger than the difference between two successive x data points."
也就是说,有一个新版本的 matplotlib finance 可以自动为您处理这个问题。您可以在此处找到新版本和文档:
https://pypi.org/project/mplfinance/
安装:pip install --upgrade mplfinance
注意:软件包名称不再包含破折号或下划线: 现在是 mplfinance(不是 mpl-finance,也不是 mpl_finance)