-
Notifications
You must be signed in to change notification settings - Fork 654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Adjust a panel's x_lim and title padding #212
Comments
Kevin, First l'd like to say that's a great looking plot. I like what you've done with mplfinance: creative and useful. Please try setting Beyond that, there are two ways that you can adjust the Figure padding surround the panels. It cannot be done per-panel, because by definition the panels are all the same width, and the padding relates to the Figure as a whole.
Please note: HTH. All the best. --Daniel |
Hi Daniel, Thank you for the suggestions. Here are some of my results: Using
|
Thank you for posting your results. Not sure why scale_padding.left != 1 and scale_padding.right != 1 are ineffective. It could be that (a) try Please try both (a) and (b) and let me know how it looks. Thanks. --Daniel |
Below are my results: # static vars
df = self.df.tail(self.recent)
mpf_style = mpf.make_mpf_style(base_mpf_style=mpf_styles[-1], rc={'figure.facecolor': '#EDEDED'})
width_config={'candle_linewidth':0.8, 'candle_width':0.525, 'volume_width': 0.525} (A)
|
Thanks. Are any of those even close to what you are trying to accomplish? Perhaps the last one (except for maybe the exact placement of the Title)? I just want to point out that I had never really intended to publicize |
Sure.
Not any of the previous tests. This version is the closest: df = self.df.tail(self.recent)
mpf_style = mpf.make_mpf_style(base_mpf_style=mpf_styles[-1], rc={'figure.facecolor': '#EDEDED'})
width_config={'candle_linewidth':0.8, 'candle_width':0.525, 'volume_width': 0.525}
mpf.plot(
df, type="candle", title=self.title,
style=mpf_style, datetime_format="%-m - %-d - %Y",
volume=True, addplot=priceta + volta + rsita + zscoreta,
figsize=(12, 10), scale_padding={'left': 1, 'top': 4, 'right': 1, 'bottom': 1},
panel_ratios=pratios, xrotation=32,
update_width_config=width_config, tight_layout=True,
) Ideally, there is adjustable padding/margin in the orange zone just like when Hope this make sense. Thanks for your time, |
Thank you. That makes sense. Until we have a
To adjust the amount of padding, modify the number you pass into When I do the above on my own chart it looks like this: |
Thanks for the suggested work around. It's funny that you posted that. Last night I was considering doing something similar, but by adding additional empty Business days to Also it seems that I will post a chart update after some refactoring. Thanks again! |
@twopirllc yes, there are already two issues requesting the various will do it, but not yet sure how soon; maybe within the next two to three months. in the meantime, generating line data and plotting that data on any panel with |
Hello @DanielGoldfarb, Sorry it has taken so long to get back to you with an example. I had to create some preliminary code in my project. Anyhow, here is a basic chart with right padding with future dates and the code I used: class Chart(object):
# ...
def _right_pad_df(self, df: pd.DataFrame, rpad: int, delta_unit: str = "D", range_freq: str = "B"):
if rpad > 0:
dfpad = df[-rpad:].copy()
dfpad.iloc[:,:] = np.NaN
df_frequency = df.index.value_counts().mode()[0] # Most common frequency
freq_delta = pd.Timedelta(df_frequency, unit=delta_unit)
new_dr = pd.date_range(start=df.index[-1] + freq_delta, periods=rpad, freq=range_freq)
dfpad.index = new_dr # Update the padded index with new dates
df = df.append(dfpad)
return df
def _plot(self, df: pd.DataFrame, plot_ratios: tuple = (12, 1.7), **kwargs):
if df.empty:
print(f"[X] DataFrame is missing!")
return
if not isinstance(plot_ratios, tuple):
print(f"[X] plot_ratios must be a tuple")
return
ticker = df.ticker
rpad = kwargs["rpad"] if "rpad" in kwargs else self.rpad
df = self._right_pad_df(df, rpad)
df = df.tail(self.last)
mpf_style = mpf.make_mpf_style(base_mpf_style=mpf_styles[-1], rc={'figure.facecolor': '#EDEDED'})
width_config={'candle_linewidth':0.8, 'candle_width':0.525, 'volume_width': 0.525}
mpf.plot(
df, type="candle", title=ticker,
style=mpf_style, datetime_format="%-m/%-d/%Y",
volume=True,
figsize=(12, 10), scale_padding={'left': 1, 'top': 4, 'right': 1, 'bottom': 1},
panel_ratios=plot_ratios, xrotation=15,
update_width_config=width_config, tight_layout=True,
) Thanks again for your time and expertise. |
kwarg |
Great! Thank you for your time and excellence. Regards, |
Hello @DanielGoldfarb,
Thanks for reviving mplfinance and making it better! I like the new panel additions. They are awesome!
Is your feature request related to a problem? Please describe.
I was able to target
mpf.make_addplot(ylim: tuple))
to adjust a panel's top and bottom ylim's so the panel's are not too close. Is it possible to at least setxlim=(mpf.minx, 0.9 * mpf.max)
?The bottom padding for title seems large. Possible bug? 🤷 Where
self.title = "SPY (D)"
.Here is the heart of the mpf plot code for the chart below:
Describe the solution you'd like
Ideally, I would like the ability to adjust at least the left padding of each panel. Or a
tight_layout
with an adjustable right padding for each panel.Thanks for your time,
KJ
The text was updated successfully, but these errors were encountered: