Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 624d161

Browse files
style enhancements; and new styles from Chandrakant
1 parent 111a0a5 commit 624d161

File tree

5 files changed

+264
-19
lines changed

5 files changed

+264
-19
lines changed

‎examples/scratch_pad/issues/issue#241_loop_all_styles.ipynb

Lines changed: 180 additions & 13 deletions
Large diffs are not rendered by default.

‎src/mplfinance/_styledata/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from mplfinance._styledata import binance
1717
from mplfinance._styledata import kenan
1818
from mplfinance._styledata import ibd
19+
from mplfinance._styledata import binancedark
20+
from mplfinance._styledata import tradingview
1921

2022
_style_names = [n for n in dir() if not n.startswith('_')]
2123

@@ -25,19 +27,29 @@
2527
eval(cmd)
2628

2729
def _validate_style(style):
30+
# Check for mandatory style keys:
2831
keys = ['base_mpl_style','marketcolors','mavcolors','y_on_right',
2932
'gridcolor','gridstyle','facecolor','rc' ]
3033
for key in keys:
3134
if key not in style.keys():
3235
err = f'Key "{key}" not found in style:\n\n {style}'
3336
raise ValueError(err)
3437

38+
# Check for mandatory marketcolor keys:
3539
mktckeys = ['candle','edge','wick','ohlc','volume','alpha']
3640
for key in mktckeys:
3741
if key not in style['marketcolors'].keys():
3842
err = f'Key "{key}" not found in marketcolors for style:\n\n {style}'
3943
raise ValueError(err)
4044

45+
# The following keys are not mandatory in the style file,
46+
# but maybe mandatory in the code (to keep the code simpler)
47+
# so we set default values here:
48+
if 'vcedge' not in style['marketcolors']:
49+
style['marketcolors']['vcedge'] = style['marketcolors']['volume']
50+
if 'vcdopcod' not in style['marketcolors']:
51+
style['marketcolors']['vcdopcod'] = False
52+
4153
#print('type(_styles)=',type(_styles))
4254
#print('_styles=',_styles)
4355
for s in _styles.keys():
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
style = dict(style_name = 'binancedark',
2+
base_mpl_style= 'dark_background',
3+
marketcolors = {'candle' : {'up': '#3dc985', 'down': '#ef4f60'},
4+
'edge' : {'up': '#3dc985', 'down': '#ef4f60'},
5+
'wick' : {'up': '#3dc985', 'down': '#ef4f60'},
6+
'ohlc' : {'up': 'green', 'down': 'red'},
7+
'volume' : {'up': '#247252', 'down': '#82333f'},
8+
'vcedge' : {'up': '#247252', 'down': '#82333f'},
9+
'vcdopcod' : False,
10+
'alpha' : 1.0,
11+
},
12+
mavcolors = ['#ffc201','#ff10ff','#cd0468','#1f77b4',
13+
'#ff7f0e','#2ca02c','#40e0d0'],
14+
y_on_right = True,
15+
gridcolor = None,
16+
gridstyle = '--',
17+
facecolor = None,
18+
rc = [ ('axes.grid','True'),
19+
('axes.grid.axis' , 'y'),
20+
('axes.edgecolor' , '#474d56' ),
21+
('axes.titlecolor','red'),
22+
('figure.titlesize', 'x-large' ),
23+
('figure.titleweight','semibold'),
24+
('figure.facecolor', '#0a0a0a' ),
25+
],
26+
base_mpf_style= 'binancedark'
27+
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
style = dict(style_name = 'tradingview',
2+
base_mpl_style= 'fast',
3+
marketcolors = {'candle' : {'up': '#26a69a', 'down': '#ef5350'},
4+
'edge' : {'up': '#26a69a', 'down': '#ef5350'},
5+
'wick' : {'up': '#26a69a', 'down': '#ef5350'},
6+
'ohlc' : {'up': '#26a69a', 'down': '#ef5350'},
7+
'volume' : {'up': '#26a69a', 'down': '#ef5350'},
8+
'vcedge' : {'up': 'white' , 'down': 'white' },
9+
'vcdopcod' : False,
10+
'alpha' : 1.0,
11+
'volume_alpha': 0.65,
12+
},
13+
mavcolors = ['#2962ff','#2962ff',],
14+
y_on_right = True,
15+
gridcolor = None,
16+
gridstyle = '--',
17+
facecolor = None,
18+
rc = [ ('axes.grid','True'),
19+
('axes.edgecolor' , 'grey' ),
20+
('axes.titlecolor','red'),
21+
('figure.titlesize', 'x-large' ),
22+
('figure.titleweight','semibold'),
23+
('figure.facecolor', 'white' ),
24+
],
25+
base_mpf_style = 'tradingview'
26+
)

‎src/mplfinance/plotting.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def _valid_plot_kwargs():
383383
'Validator' : lambda value: isinstance(value, (list,tuple)) and len(value) == 2
384384
and all([isinstance(v,(int,float)) for v in value])},
385385

386-
'volume_alpha' : { 'Default' : 1, # alpha of Volume bars
386+
'volume_alpha' : { 'Default' : None, # alpha of Volume bars
387387
'Description' : 'opacity for Volume bar: 0.0 (transparent) to 1.0 (opaque)',
388388
'Validator' : lambda value: isinstance(value,(int,float)) or
389389
all([isinstance(v,(int,float)) for v in value]) },
@@ -673,7 +673,8 @@ def plot( data, **kwargs ):
673673

674674
datalen = len(xdates)
675675
if config['volume']:
676-
vup,vdown = style['marketcolors']['volume'].values()
676+
mc = style['marketcolors']
677+
vup,vdown = mc['volume'].values()
677678
#-- print('vup,vdown=',vup,vdown)
678679
vcolors = _updown_colors(vup, vdown, opens, closes, use_prev_close=style['marketcolors']['vcdopcod'])
679680
#-- print('len(vcolors),len(opens),len(closes)=',len(vcolors),len(opens),len(closes))
@@ -682,9 +683,21 @@ def plot( data, **kwargs ):
682683
w = config['_width_config']['volume_width']
683684
lw = config['_width_config']['volume_linewidth']
684685

685-
adjc = _adjust_color_brightness(vcolors,0.90)
686-
valp = config['volume_alpha']
687-
volumeAxes.bar(xdates,volumes,width=w,linewidth=lw,color=vcolors,ec=adjc,alpha=valp)
686+
veup, vedown = mc['vcedge'].values()
687+
if mc['volume'] == mc['vcedge']:
688+
edgecolors = _adjust_color_brightness(vcolors,0.90)
689+
elif veup != vedown:
690+
edgecolors = _updown_colors(veup, vedown, opens, closes, use_prev_close=style['marketcolors']['vcdopcod'])
691+
else:
692+
edgecolors = veup
693+
694+
if config['volume_alpha']:
695+
valp = config['volume_alpha']
696+
elif 'volume_alpha' in mc:
697+
valp = mc['volume_alpha']
698+
else:
699+
valp = 1.0
700+
volumeAxes.bar(xdates,volumes,width=w,linewidth=lw,color=vcolors,ec=edgecolors,alpha=valp)
688701
if config['volume_ylim'] is not None:
689702
vymin = config['volume_ylim'][0]
690703
vymax = config['volume_ylim'][1]
@@ -911,7 +924,7 @@ def plot( data, **kwargs ):
911924
else:
912925
title = config['title'] # config['title'] is a string
913926
fig.suptitle(title,**title_kwargs)
914-
927+
915928

916929
if config['axtitle'] is not None:
917930
axA1.set_title(config['axtitle'])

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /