简体   繁体   English

如何使用matplotlib向烛台添加边框或边缘颜色?

[英]How to add a border or edge color to candlesticks with matplotlib?

I'm trying to add a black border around the candlesticks in a matplotlib plot. 我正在尝试在matplotlib图中的烛台周围添加黑色边框。 Here's the code I've tried, which resulted in an error ( TypeError: candlestick_ohlc() got an unexpected keyword argument 'edgecolor' ) 这是我尝试过的代码,导致错误( TypeError: candlestick_ohlc() got an unexpected keyword argument 'edgecolor'

candlestick_ohlc(ax2, ohlc, width=0.9, edgecolor = 'k', colorup='g', colordown='r')

edgecolor = 'k' is unrecognized. edgecolor = 'k'无法识别。 I've used it on the fill_between function before but the candlestick_ohlc won't accept it. 我用它在fill_between函数之前,但candlestick_ohlc不会接受它。

this is the result I want: 这是我想要的结果:

在此处输入图片说明

this is what I currently have: 这是我目前拥有的:

在此处输入图片说明

thank you! 谢谢!

From the documentation , candlestick_ohlc returns a tuple of lists, one list for the lines, one for the rectangles. 从文档中candlestick_ohlc返回一个列表的元组,一个列表为线,一个为矩形。 You can store each of these lists and then iterate over each element to change their properties. 您可以存储每个列表,然后遍历每个元素以更改其属性。

ls, rs = candlestick_ohlc(ax, quotes, width=0.6, colorup='b', colordown='g')

for r in rs:
    r.set_edgecolor('r')
    r.set_linewidth(1.)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM