Skip to content

Commit 2a57029

Browse files
package mpf_collections
1 parent ccded3b commit 2a57029

File tree

3 files changed

+43
-35
lines changed

3 files changed

+43
-35
lines changed

src/mplfinance/_panels.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def _create_panel_axes( figure, ha, hb, hc, panel_order ):
158158

159159
return axA1, axA2, axB1, axB2, axC1, axC2, actual_order
160160

161-
def _adjust_ticklabels_per_bottom_panel(axA1,axB1,axC1,actual_order,hb,hc,formatter):
161+
def _adjust_ticklabels_per_bottom_panel(axA1,axB1,axC1,actual_order,hb,hc,formatter,rotation=45):
162162
"""
163163
Determine which panel is on the bottom, then display ticklabels
164164
for the bottom panel Axes, and NOT for the other Axes.
@@ -169,7 +169,7 @@ def _adjust_ticklabels_per_bottom_panel(axA1,axB1,axC1,actual_order,hb,hc,format
169169

170170
bottom_panel = actual_order[-1]
171171
if bottom_panel == 'A':
172-
axA1.tick_params(axis='x', rotation=45)
172+
axA1.tick_params(axis='x', rotation=rotation)
173173
if hb > 0:
174174
#plt.setp(axB1.get_xticklabels(), visible=False)
175175
#axB1.tick_params(axis='x', visible=False)
@@ -179,7 +179,7 @@ def _adjust_ticklabels_per_bottom_panel(axA1,axB1,axC1,actual_order,hb,hc,format
179179
#axC1.tick_params(axis='x', visible=False)
180180
axC1.tick_params(axis='x', labelbottom=False)
181181
elif bottom_panel == 'B':
182-
axB1.tick_params(axis='x', rotation=45)
182+
axB1.tick_params(axis='x', rotation=rotation)
183183
axB1.xaxis.set_major_formatter(formatter)
184184
#plt.setp(axA1.get_xticklabels(), visible=False)
185185
#axA1.tick_params(axis='x', visible=False)
@@ -189,7 +189,7 @@ def _adjust_ticklabels_per_bottom_panel(axA1,axB1,axC1,actual_order,hb,hc,format
189189
#axC1.tick_params(axis='x', visible=False)
190190
axC1.tick_params(axis='x', labelbottom=False)
191191
elif bottom_panel == 'C':
192-
axC1.tick_params(axis='x', rotation=45)
192+
axC1.tick_params(axis='x', rotation=rotation)
193193
axC1.xaxis.set_major_formatter(formatter)
194194
#plt.setp(axA1.get_xticklabels(), visible=False)
195195
#plt.setp(axB1.get_xticklabels(), visible=False)

src/mplfinance/_utils.py

+21
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,27 @@ def roundTime(dt=None, roundTo=60):
8585
rounding = (seconds+roundTo/2) // roundTo * roundTo
8686
return dt + datetime.timedelta(0,rounding-seconds,-dt.microsecond)
8787

88+
def _construct_mpf_collections(ptype,dates,xdates,opens,highs,lows,closes,volumes,config,style):
89+
collections = None
90+
if ptype == 'candle' or ptype == 'candlestick':
91+
collections = _construct_candlestick_collections(xdates, opens, highs, lows, closes,
92+
marketcolors=style['marketcolors'] )
93+
elif ptype == 'ohlc' or ptype == 'bars' or ptype == 'ohlc_bars':
94+
collections = _construct_ohlc_collections(xdates, opens, highs, lows, closes,
95+
marketcolors=style['marketcolors'] )
96+
elif ptype == 'renko':
97+
collections = _construct_renko_collections(
98+
dates, highs, lows, volumes, config['renko_params'], closes, marketcolors=style['marketcolors'])
99+
100+
elif ptype == 'pnf':
101+
collections = _construct_pointnfig_collections(
102+
dates, highs, lows, volumes, config['pnf_params'], closes, marketcolors=style['marketcolors'])
103+
else:
104+
raise TypeError('Unknown ptype="',str(ptype),'"')
105+
106+
return collections
107+
108+
88109
def _calculate_atr(atr_length, highs, lows, closes):
89110
"""Calculate the average true range
90111
atr_length : time period to calculate over

src/mplfinance/plotting.py

+18-31
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
#from pandas.plotting import register_matplotlib_converters
1414
#register_matplotlib_converters()
1515

16-
from mplfinance._utils import _construct_ohlc_collections
17-
from mplfinance._utils import _construct_candlestick_collections
18-
from mplfinance._utils import _construct_renko_collections
19-
from mplfinance._utils import _construct_pointnfig_collections
16+
#from mplfinance._utils import _construct_ohlc_collections
17+
#from mplfinance._utils import _construct_candlestick_collections
18+
#from mplfinance._utils import _construct_renko_collections
19+
#from mplfinance._utils import _construct_pointnfig_collections
2020
from mplfinance._utils import _construct_aline_collections
2121
from mplfinance._utils import _construct_hline_collections
2222
from mplfinance._utils import _construct_vline_collections
2323
from mplfinance._utils import _construct_tline_collections
24+
from mplfinance._utils import _construct_mpf_collections
2425

2526
from mplfinance._utils import _updown_colors
2627
from mplfinance._utils import IntegerIndexDateTimeFormatter
@@ -186,7 +187,7 @@ def _valid_plot_kwargs():
186187
'datetime_format' : { 'Default' : None,
187188
'Validator' : lambda value: isinstance(value,str) },
188189

189-
'x_rotation' : { 'Default' : None,
190+
'xrotation' : { 'Default' : 45,
190191
'Validator' : lambda value: isinstance(value,(int,float)) },
191192
}
192193

@@ -248,37 +249,22 @@ def plot( data, **kwargs ):
248249

249250
ptype = config['type']
250251

251-
if ptype not in VALID_PMOVE_TYPES:
252-
if config['show_nontrading']:
253-
formatter = mdates.DateFormatter(fmtstring)
254-
xdates = dates
255-
else:
256-
formatter = IntegerIndexDateTimeFormatter(dates, fmtstring)
257-
xdates = np.arange(len(dates))
258-
axA1.xaxis.set_major_formatter(formatter)
252+
if config['show_nontrading']:
253+
formatter = mdates.DateFormatter(fmtstring)
254+
xdates = dates
255+
else:
256+
formatter = IntegerIndexDateTimeFormatter(dates, fmtstring)
257+
xdates = np.arange(len(dates))
258+
axA1.xaxis.set_major_formatter(formatter)
259259

260260
collections = None
261-
if ptype == 'candle' or ptype == 'candlestick':
262-
collections = _construct_candlestick_collections(xdates, opens, highs, lows, closes,
263-
marketcolors=style['marketcolors'] )
264-
elif ptype == 'ohlc' or ptype == 'bars' or ptype == 'ohlc_bars':
265-
collections = _construct_ohlc_collections(xdates, opens, highs, lows, closes,
266-
marketcolors=style['marketcolors'] )
267-
elif ptype == 'renko':
268-
collections, new_dates, volumes, brick_values, size = _construct_renko_collections(
269-
dates, highs, lows, volumes, config['renko_params'], closes, marketcolors=style['marketcolors'])
270-
271-
elif ptype == 'pnf':
272-
collections, new_dates, volumes, brick_values, size = _construct_pointnfig_collections(
273-
dates, highs, lows, volumes, config['pnf_params'], closes, marketcolors=style['marketcolors'])
274-
275-
elif ptype == 'line':
261+
if ptype == 'line':
276262
axA1.plot(xdates, closes, color=config['linecolor'])
277-
278263
else:
279-
raise ValueError('Unrecognized plot type = "'+ ptype + '"')
264+
collections =_construct_mpf_collections(ptype,dates,xdates,opens,highs,lows,closes,volumes,config,style)
280265

281266
if ptype in VALID_PMOVE_TYPES:
267+
collections, new_dates, volumes, brick_values, size = collections
282268
formatter = IntegerIndexDateTimeFormatter(new_dates, fmtstring)
283269
xdates = np.arange(len(new_dates))
284270
axA1.xaxis.set_major_formatter(formatter)
@@ -395,7 +381,8 @@ def plot( data, **kwargs ):
395381
maxy = config['set_ylim_panelB'][1]
396382
axB1.set_ylim( miny, maxy )
397383

398-
_adjust_ticklabels_per_bottom_panel(axA1,axB1,axC1,actual_order,hb,hc,formatter)
384+
xrotation = config['xrotation']
385+
_adjust_ticklabels_per_bottom_panel(axA1,axB1,axC1,actual_order,hb,hc,formatter,xrotation)
399386

400387
used_axA2 = False
401388
used_axB2 = False

0 commit comments

Comments
 (0)