Skip to content

Commit 403efe6

Browse files
committed
fix rectangles caused by stretching small x-axis
1 parent cc8682d commit 403efe6

File tree

3 files changed

+73
-51
lines changed

3 files changed

+73
-51
lines changed

examples/renko_charts.ipynb

Lines changed: 64 additions & 44 deletions
Large diffs are not rendered by default.

src/mplfinance/_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def _construct_renko_collections(dates, highs, lows, volumes, config_renko_param
395395
for i in range(len(cdiff)):
396396
num_bricks = abs(int(cdiff[i]))
397397
curr_diff_sign = cdiff[i]/abs(cdiff[i])
398-
if last_diff_sign != 0 and curr_diff_sign != last_diff_sign:
398+
if last_diff_sign != 0 and num_bricks > 0 and curr_diff_sign != last_diff_sign:
399399
num_bricks -= 1
400400
last_diff_sign = curr_diff_sign
401401

src/mplfinance/plotting.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,14 @@ def plot( data, **kwargs ):
314314
retdict['mav' + str(mavgs[i])] = mavprices
315315

316316
avg_dist_between_points = (xdates[-1] - xdates[0]) / float(len(xdates))
317-
minx = xdates[0] - avg_dist_between_points
318-
maxx = xdates[-1] + avg_dist_between_points
319-
miny = min([low for low in lows if low != -1])
320-
maxy = max([high for high in highs if high != -1])
321-
corners = (minx, miny), (maxx, maxy)
322-
ax1.update_datalim(corners)
317+
318+
if ptype not in VALID_PMOVE_TYPES:
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)
323325

324326
if config['volume']:
325327
vup,vdown = style['marketcolors']['volume'].values()

0 commit comments

Comments
 (0)