16
16
from mplfinance ._utils import _construct_candlestick_collections
17
17
from mplfinance ._utils import _construct_renko_collections
18
18
19
+ from mplfinance ._utils import renko_reformat_ydata
19
20
from mplfinance ._utils import _updown_colors
20
21
from mplfinance ._utils import IntegerIndexDateTimeFormatter
21
22
@@ -222,12 +223,10 @@ def plot( data, **kwargs ):
222
223
for apdict in addplot :
223
224
if apdict ['panel' ] == 'lower' :
224
225
need_lower_panel = True
225
- break
226
-
227
- ptype = config ['type' ]
226
+ break
228
227
229
228
# fig.add_axes( [left, bottom, width, height] ) ... numbers are fraction of fig
230
- if need_lower_panel or config ['volume' ] and ptype is not 'renko' :
229
+ if need_lower_panel or config ['volume' ]:
231
230
ax1 = fig .add_axes ( [0.15 , 0.38 , 0.70 , 0.50 ] )
232
231
ax2 = fig .add_axes ( [0.15 , 0.18 , 0.70 , 0.20 ], sharex = ax1 )
233
232
plt .xticks (rotation = 45 ) # must do this after creation of axis, and
@@ -258,7 +257,7 @@ def plot( data, **kwargs ):
258
257
else :
259
258
fmtstring = '%b %d'
260
259
261
-
260
+ ptype = config [ 'type' ]
262
261
263
262
if ptype is not 'renko' :
264
263
if config ['show_nontrading' ]:
@@ -270,10 +269,6 @@ def plot( data, **kwargs ):
270
269
271
270
ax1 .xaxis .set_major_formatter (formatter )
272
271
273
-
274
-
275
- renko_params = config ['renko_params' ]
276
-
277
272
collections = None
278
273
if ptype == 'candle' or ptype == 'candlestick' :
279
274
collections = _construct_candlestick_collections (xdates , opens , highs , lows , closes ,
@@ -282,8 +277,8 @@ def plot( data, **kwargs ):
282
277
collections = _construct_ohlc_collections (xdates , opens , highs , lows , closes ,
283
278
marketcolors = style ['marketcolors' ] )
284
279
elif ptype == 'renko' :
285
- renko_params = _process_kwargs (kwargs ['renko_params' ] if 'renko_params' in kwargs else dict () , _valid_renko_kwargs ())
286
- collections , new_dates = _construct_renko_collections (dates , highs , lows , renko_params , closes ,
280
+ renko_params = _process_kwargs (config ['renko_params' ], _valid_renko_kwargs ())
281
+ collections , new_dates , volumes = _construct_renko_collections (dates , highs , lows , volumes , renko_params , closes ,
287
282
marketcolors = style ['marketcolors' ] )
288
283
289
284
formatter = IntegerIndexDateTimeFormatter (new_dates , fmtstring )
@@ -312,25 +307,23 @@ def plot( data, **kwargs ):
312
307
mavc = None
313
308
314
309
for mav in mavgs :
315
- mavprices = data ['Close' ].rolling (mav ).mean ().values
310
+ mavprices = data ['Close' ].rolling (mav ).mean ().values
311
+ if ptype == 'renko' :
312
+ mavprices = renko_reformat_ydata (mavprices , new_dates , dates )
316
313
if mavc :
317
314
ax1 .plot (xdates , mavprices , color = next (mavc ))
318
315
else :
319
316
ax1 .plot (xdates , mavprices )
320
317
321
-
322
- if ptype == 'renko' :
323
- ax1 .autoscale ()
324
- else :
325
- avg_dist_between_points = (xdates [- 1 ] - xdates [0 ]) / float (len (xdates ))
326
- minx = xdates [0 ] - avg_dist_between_points
327
- maxx = xdates [- 1 ] + avg_dist_between_points
328
- miny = min ([low for low in lows if low != - 1 ])
329
- maxy = max ([high for high in highs if high != - 1 ])
330
- corners = (minx , miny ), (maxx , maxy )
331
- ax1 .update_datalim (corners )
332
-
333
- if config ['volume' ] and ptype is not 'renko' :
318
+ avg_dist_between_points = (xdates [- 1 ] - xdates [0 ]) / float (len (xdates ))
319
+ minx = xdates [0 ] - avg_dist_between_points
320
+ maxx = xdates [- 1 ] + avg_dist_between_points
321
+ miny = min ([low for low in lows if low != - 1 ])
322
+ maxy = max ([high for high in highs if high != - 1 ])
323
+ corners = (minx , miny ), (maxx , maxy )
324
+ ax1 .update_datalim (corners )
325
+
326
+ if config ['volume' ]:
334
327
vup ,vdown = style ['marketcolors' ]['volume' ].values ()
335
328
#-- print('vup,vdown=',vup,vdown)
336
329
vcolors = _updown_colors (vup , vdown , opens , closes , use_prev_close = style ['marketcolors' ]['vcdopcod' ])
@@ -415,6 +408,9 @@ def plot( data, **kwargs ):
415
408
if ax == ax4 :
416
409
used_ax4 = True
417
410
411
+ if ptype == 'renko' :
412
+ ydata = renko_reformat_ydata (ydata , new_dates , dates )
413
+
418
414
if apdict ['scatter' ]:
419
415
size = apdict ['markersize' ]
420
416
mark = apdict ['marker' ]
@@ -449,7 +445,7 @@ def plot( data, **kwargs ):
449
445
ax4 .yaxis .set_label_position ('right' )
450
446
ax4 .yaxis .tick_right ()
451
447
452
- if need_lower_panel or config ['volume' ] and ptype is not 'renko' :
448
+ if need_lower_panel or config ['volume' ]:
453
449
ax1 .spines ['bottom' ].set_linewidth (0.25 )
454
450
ax2 .spines ['top' ].set_linewidth (0.25 )
455
451
plt .setp (ax1 .get_xticklabels (), visible = False )
@@ -476,7 +472,7 @@ def plot( data, **kwargs ):
476
472
477
473
ax1 .set_ylabel (config ['ylabel' ])
478
474
479
- if config ['volume' ] and ptype is not 'renko' :
475
+ if config ['volume' ]:
480
476
ax2 .figure .canvas .draw () # This is needed to calculate offset
481
477
offset = ax2 .yaxis .get_major_formatter ().get_offset ()
482
478
ax2 .yaxis .offsetText .set_visible (False )
0 commit comments