|
32 | 32 |
|
33 | 33 | from mplfinance import _styles
|
34 | 34 |
|
35 |
| -from mplfinance._arg_validators import _check_and_prepare_data, _mav_validator |
| 35 | +from mplfinance._arg_validators import _check_and_prepare_data, _mav_validator, _label_validator |
36 | 36 | from mplfinance._arg_validators import _get_valid_plot_types, _fill_between_validator
|
37 | 37 | from mplfinance._arg_validators import _process_kwargs, _validate_vkwargs_dict
|
38 | 38 | from mplfinance._arg_validators import _kwarg_not_implemented, _bypass_kwarg_validation
|
@@ -1093,32 +1093,41 @@ def _addplot_columns(panid,panels,ydata,apdict,xdates,config):
|
1093 | 1093 | mark = apdict['marker']
|
1094 | 1094 | color = apdict['color']
|
1095 | 1095 | alpha = apdict['alpha']
|
| 1096 | + labels = apdict['labels'] |
1096 | 1097 | edgecolors = apdict['edgecolors']
|
1097 | 1098 | linewidths = apdict['linewidths']
|
1098 | 1099 |
|
1099 | 1100 | if isinstance(mark,(list,tuple,np.ndarray)):
|
1100 | 1101 | _mscatter(xdates, ydata, ax=ax, m=mark, s=size, color=color, alpha=alpha, edgecolors=edgecolors, linewidths=linewidths)
|
1101 | 1102 | else:
|
1102 | 1103 | ax.scatter(xdates, ydata, s=size, marker=mark, color=color, alpha=alpha, edgecolors=edgecolors, linewidths=linewidths)
|
| 1104 | + if labels is not None: |
| 1105 | + ax.legend(labels=labels) |
1103 | 1106 | elif aptype == 'bar':
|
1104 | 1107 | width = 0.8 if apdict['width'] is None else apdict['width']
|
1105 | 1108 | bottom = apdict['bottom']
|
1106 | 1109 | color = apdict['color']
|
1107 | 1110 | alpha = apdict['alpha']
|
1108 | 1111 | ax.bar(xdates,ydata,width=width,bottom=bottom,color=color,alpha=alpha)
|
| 1112 | + if apdict['labels'] is not None: |
| 1113 | + ax.legend(labels=apdict['labels']) |
1109 | 1114 | elif aptype == 'line':
|
1110 | 1115 | ls = apdict['linestyle']
|
1111 | 1116 | color = apdict['color']
|
1112 | 1117 | width = apdict['width'] if apdict['width'] is not None else 1.6*config['_width_config']['line_width']
|
1113 | 1118 | alpha = apdict['alpha']
|
1114 | 1119 | ax.plot(xdates,ydata,linestyle=ls,color=color,linewidth=width,alpha=alpha)
|
| 1120 | + if apdict['labels'] is not None: |
| 1121 | + ax.legend(labels=apdict['labels']) |
1115 | 1122 | elif aptype == 'step':
|
1116 | 1123 | stepwhere = apdict['stepwhere']
|
1117 | 1124 | ls = apdict['linestyle']
|
1118 | 1125 | color = apdict['color']
|
1119 | 1126 | width = apdict['width'] if apdict['width'] is not None else 1.6*config['_width_config']['line_width']
|
1120 | 1127 | alpha = apdict['alpha']
|
1121 | 1128 | ax.step(xdates,ydata,where = stepwhere,linestyle=ls,color=color,linewidth=width,alpha=alpha)
|
| 1129 | + if apdict['labels'] is not None: |
| 1130 | + ax.legend(labels=apdict['labels']) |
1122 | 1131 | else:
|
1123 | 1132 | raise ValueError('addplot type "'+str(aptype)+'" NOT yet supported.')
|
1124 | 1133 |
|
@@ -1371,6 +1380,9 @@ def _valid_addplot_kwargs():
|
1371 | 1380 | 'fill_between': { 'Default' : None, # added by Wen
|
1372 | 1381 | 'Description' : " fill region",
|
1373 | 1382 | 'Validator' : _fill_between_validator },
|
| 1383 | + "labels" : { 'Default' : None, |
| 1384 | + 'Description' : 'Labels for the added plot.', |
| 1385 | + 'Validator' : _label_validator }, |
1374 | 1386 |
|
1375 | 1387 | }
|
1376 | 1388 |
|
|
0 commit comments