Merge pull request #5003 from rokups/rk/plotting
Indicator plotting improvement
This commit is contained in:
@@ -96,20 +96,34 @@ def add_indicators(fig, row, indicators: Dict[str, Dict], data: pd.DataFrame) ->
|
||||
Dict key must correspond to dataframe column.
|
||||
:param data: candlestick DataFrame
|
||||
"""
|
||||
plot_kinds = {
|
||||
'scatter': go.Scatter,
|
||||
'bar': go.Bar,
|
||||
}
|
||||
for indicator, conf in indicators.items():
|
||||
logger.debug(f"indicator {indicator} with config {conf}")
|
||||
if indicator in data:
|
||||
kwargs = {'x': data['date'],
|
||||
'y': data[indicator].values,
|
||||
'mode': 'lines',
|
||||
'name': indicator
|
||||
}
|
||||
if 'color' in conf:
|
||||
kwargs.update({'line': {'color': conf['color']}})
|
||||
scatter = go.Scatter(
|
||||
**kwargs
|
||||
)
|
||||
fig.add_trace(scatter, row, 1)
|
||||
|
||||
plot_type = conf.get('type', 'scatter')
|
||||
color = conf.get('color')
|
||||
if plot_type == 'bar':
|
||||
kwargs.update({'marker_color': color or 'DarkSlateGrey',
|
||||
'marker_line_color': color or 'DarkSlateGrey'})
|
||||
else:
|
||||
if color:
|
||||
kwargs.update({'line': {'color': color}})
|
||||
kwargs['mode'] = 'lines'
|
||||
if plot_type != 'scatter':
|
||||
logger.warning(f'Indicator {indicator} has unknown plot trace kind {plot_type}'
|
||||
f', assuming "scatter".')
|
||||
|
||||
kwargs.update(conf.get('plotly', {}))
|
||||
trace = plot_kinds[plot_type](**kwargs)
|
||||
fig.add_trace(trace, row, 1)
|
||||
else:
|
||||
logger.info(
|
||||
'Indicator "%s" ignored. Reason: This indicator is not found '
|
||||
|
Reference in New Issue
Block a user