Skip to content

Commit 9b95dca

Browse files
authored
Merge pull request #3 from matplotlib/master
Merge with upstream
2 parents b740d50 + 1cc114a commit 9b95dca

File tree

5 files changed

+1049
-21
lines changed

5 files changed

+1049
-21
lines changed

RELEASE_NOTES.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
####
22
---
33

4-
### <a name="v0.12.7a11"></a>v0.12.7a11 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; To Be released 2021-03-30
4+
### <a name="v0.12.7a12"></a>v0.12.7a12 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; released 2021-04-09
55

6+
- <a name="v0.12.7a12"></a>v0.12.7a12 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; merged 2021-04-08
7+
- Fixed kwarg **`return_calculated_values`**
8+
- It was *not* returning all values for `type='pnf'` (point and figure).
9+
- See **[stackoverflow 66991998](https://stackoverflow.com/questions/66991998/)** for more information.
610
- <a name="v0.12.7a11"></a>v0.12.7a11 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; merged 2021-03-26
711
- Prior to this version, **`xlim`** kwarg accepted only float or int:
812
- float as matplotlib date; (only when `show_nontrading=True`)

examples/scratch_pad/price-movement_ret_calc_vals.ipynb

Lines changed: 1006 additions & 0 deletions
Large diffs are not rendered by default.

src/mplfinance/_utils.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,9 @@ def _construct_renko_collections(dates, highs, lows, volumes, config_renko_param
857857
edgecolors=edge_colors,
858858
linewidths=lw
859859
)
860-
return [rectCollection,], new_dates, new_volumes, brick_values, brick_size
860+
calculated_values = dict(dates=new_dates,volumes=new_volumes,
861+
values=brick_values,size=brick_size)
862+
return [rectCollection,], calculated_values
861863

862864

863865
def _construct_pointnfig_collections(dates, highs, lows, volumes, config_pointnfig_params, closes, marketcolors=None):
@@ -1052,7 +1054,7 @@ def _construct_pointnfig_collections(dates, highs, lows, volumes, config_pointnf
10521054
box_values = [] # y values for the boxes
10531055
circle_patches = [] # list of circle patches to be used to create the cirCollection
10541056
line_seg = [] # line segments that make up the Xs
1055-
1057+
10561058
for index, difference in enumerate(boxes):
10571059
diff = abs(difference)
10581060

@@ -1061,9 +1063,9 @@ def _construct_pointnfig_collections(dates, highs, lows, volumes, config_pointnf
10611063

10621064
x = [index] * (diff)
10631065
y = [curr_price + (i * box_size * sign) for i in range(start_iteration, diff+start_iteration)]
1064-
1066+
10651067
curr_price += (box_size * sign * (diff))
1066-
box_values.append(sum(y) / len(y))
1068+
box_values.append( y )
10671069

10681070
for i in range(len(x)): # x and y have the same length
10691071
height = box_size * 0.85
@@ -1090,7 +1092,9 @@ def _construct_pointnfig_collections(dates, highs, lows, volumes, config_pointnf
10901092
linewidths=lw,
10911093
antialiaseds=useAA
10921094
)
1093-
return [cirCollection, xCollection], new_dates, new_volumes, box_values, box_size
1095+
calculated_values = dict(dates=new_dates,counts=boxes,values=box_values,
1096+
volumes=new_volumes,size=box_size)
1097+
return [cirCollection, xCollection], calculated_values
10941098

10951099

10961100
def _construct_aline_collections(alines, dtix=None):

src/mplfinance/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
version_info = (0, 12, 7, 'alpha', 11)
2+
version_info = (0, 12, 7, 'alpha', 12)
33

44
_specifier_ = {'alpha': 'a','beta': 'b','candidate': 'rc','final': ''}
55

src/mplfinance/plotting.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,25 @@ def plot( data, **kwargs ):
400400
collections =_construct_mpf_collections(ptype,dates,xdates,opens,highs,lows,closes,volumes,config,style)
401401

402402
if ptype in VALID_PMOVE_TYPES:
403-
collections, new_dates, volumes, brick_values, size = collections
404-
formatter = IntegerIndexDateTimeFormatter(new_dates, fmtstring)
405-
xdates = np.arange(len(new_dates))
403+
collections, calculated_values = collections
404+
volumes = calculated_values['volumes']
405+
pmove_dates = calculated_values['dates']
406+
pmove_values = calculated_values['values']
407+
if all([isinstance(v,(list,tuple)) for v in pmove_values]):
408+
pmove_avgvals = [sum(v)/len(v) for v in pmove_values]
409+
else:
410+
pmove_avgvals = pmove_values
411+
pmove_size = calculated_values['size']
412+
pmove_counts = calculated_values['counts'] if 'counts' in calculated_values else None
413+
formatter = IntegerIndexDateTimeFormatter(pmove_dates, fmtstring)
414+
xdates = np.arange(len(pmove_dates))
406415

407416
if collections is not None:
408417
for collection in collections:
409418
axA1.add_collection(collection)
410419

411420
if ptype in VALID_PMOVE_TYPES:
412-
mavprices = _plot_mav(axA1,config,xdates,brick_values)
421+
mavprices = _plot_mav(axA1,config,xdates,pmove_avgvals)
413422
else:
414423
mavprices = _plot_mav(axA1,config,xdates,closes)
415424

@@ -428,8 +437,8 @@ def plot( data, **kwargs ):
428437
_lows = lows
429438
_highs = highs
430439
else:
431-
_lows = brick_values
432-
_highs = [brick+size for brick in brick_values]
440+
_lows = pmove_avgvals
441+
_highs = [value+pmove_size for value in pmove_avgvals]
433442

434443
miny = np.nanmin(_lows)
435444
maxy = np.nanmax(_highs)
@@ -458,13 +467,18 @@ def plot( data, **kwargs ):
458467

459468
if config['return_calculated_values'] is not None:
460469
retdict = config['return_calculated_values']
461-
if ptype in VALID_PMOVE_TYPES:
462-
prekey = ptype
463-
retdict[prekey+'_bricks'] = brick_values
464-
retdict[prekey+'_dates'] = mdates.num2date(new_dates)
465-
retdict[prekey+'_size'] = size
466-
if config['volume']:
467-
retdict[prekey+'_volumes'] = volumes
470+
if ptype == 'renko':
471+
retdict['renko_bricks' ] = pmove_values
472+
retdict['renko_dates' ] = mdates.num2date(pmove_dates)
473+
retdict['renko_size' ] = pmove_size
474+
retdict['renko_volumes'] = volumes if config['volume'] else None
475+
elif ptype == 'pnf':
476+
retdict['pnf_dates' ] = mdates.num2date(pmove_dates)
477+
retdict['pnf_counts' ] = pmove_counts
478+
retdict['pnf_values' ] = pmove_values
479+
retdict['pnf_avgvals' ] = pmove_avgvals
480+
retdict['pnf_size' ] = pmove_size
481+
retdict['pnf_volumes' ] = volumes if config['volume'] else None
468482
if config['mav'] is not None:
469483
mav = config['mav']
470484
if len(mav) != len(mavprices):
@@ -480,7 +494,7 @@ def plot( data, **kwargs ):
480494
# Note: these are NOT mutually exclusive, so the order of this
481495
# if/elif is important: VALID_PMOVE_TYPES must be first.
482496
if ptype in VALID_PMOVE_TYPES:
483-
dtix = pd.DatetimeIndex([dt for dt in mdates.num2date(new_dates)])
497+
dtix = pd.DatetimeIndex([dt for dt in mdates.num2date(pmove_dates)])
484498
elif not config['show_nontrading']:
485499
dtix = data.index
486500
else:

0 commit comments

Comments
 (0)