@@ -170,8 +170,8 @@ def _updownhollow_colors(upcolor,downcolor,uphollow,downhollow,opens,closes):
170
170
return upcolor
171
171
umap = {True : upcolor , False : uphollow }
172
172
dmap = {True : downcolor , False : downhollow }
173
- _list = [ umap [cls < opn ] if cls > cls0 else dmap [cls < opn ] for opn0 ,cls0 ,opn ,cls in zip (opens [0 :- 1 ],closes [0 :- 1 ],opens [1 :],closes [1 :]) ]
174
- first = umap [ closes [0 ] < opens [0 ]]
173
+ _list = [umap [cls > opn ] if cls > cls0 else dmap [cls < opn ] for opn0 ,cls0 ,opn ,cls in zip (opens [0 :- 1 ],closes [0 :- 1 ],opens [1 :],closes [1 :]) ]
174
+ first = upcolor if closes [0 ] > opens [0 ] else downcolor
175
175
return [first ] + _list
176
176
177
177
@@ -488,6 +488,17 @@ def _construct_candlestick_collections(dates, opens, highs, lows, closes, market
488
488
return [rangeCollection , barCollection ]
489
489
490
490
491
+ def alpha_handler (color , alpha ):
492
+ """Checks the color input for an alpha value. Returns the rgba color code with lesser
493
+ of existing or provided alpha
494
+ """
495
+ color_code = mcolors .to_rgba (color )
496
+ if color_code [- 1 ] <= alpha :
497
+ return color_code
498
+ else :
499
+ return mcolors .to_rgba (color , alpha )
500
+
501
+
491
502
def _construct_hollow_candlestick_collections (dates , opens , highs , lows , closes , marketcolors = None , config = None ):
492
503
"""Represent the open, close as a bar line and high low range as a
493
504
vertical line. Same as basic candlestick, but utilizes solid and hollow candlesticks
@@ -519,7 +530,7 @@ def _construct_hollow_candlestick_collections(dates, opens, highs, lows, closes,
519
530
_check_input (opens , highs , lows , closes )
520
531
521
532
if marketcolors is None :
522
- marketcolors = _get_mpfstyle ('classic ' )['marketcolors' ]
533
+ marketcolors = _get_mpfstyle ('hollow ' )['marketcolors' ]
523
534
#print('default market colors:',marketcolors)
524
535
525
536
datalen = len (dates )
@@ -544,10 +555,13 @@ def _construct_hollow_candlestick_collections(dates, opens, highs, lows, closes,
544
555
545
556
alpha = marketcolors ['alpha' ]
546
557
547
- uc = mcolors .to_rgba (marketcolors ['candle' ][ 'up' ], alpha )
548
- dc = mcolors .to_rgba (marketcolors ['candle' ]['down' ], alpha )
549
- uh = mcolors .to_rgba (marketcolors ['candle' ]['up_hollow' ], alpha )
550
- dh = mcolors .to_rgba (marketcolors ['candle' ]['down_hollow' ], alpha )
558
+ uc = alpha_handler (marketcolors ['candle' ][ 'up' ], alpha )
559
+ dc = alpha_handler (marketcolors ['candle' ]['down' ], alpha )
560
+ try :
561
+ uh = alpha_handler (marketcolors ['hollow' ]['up' ], alpha )
562
+ dh = alpha_handler (marketcolors ['hollow' ]['down' ], alpha )
563
+ except KeyError as e :
564
+ raise Exception ('Improper style definition for hollow candle type plotting' ) from e
551
565
colors = _updownhollow_colors (uc , dc , uh , dh , opens , closes )
552
566
553
567
uc = mcolors .to_rgba (marketcolors ['edge' ][ 'up' ], 1.0 )
0 commit comments