Skip to content
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

matplotlib and mplfinance #312

Closed
david03kimo opened this issue Jan 9, 2021 · 3 comments
Closed

matplotlib and mplfinance #312

david03kimo opened this issue Jan 9, 2021 · 3 comments
Labels
question Further information is requested

Comments

@david03kimo
Copy link

david03kimo commented Jan 9, 2021

Hi,thanks for your great work.

I am newbie to matplotlib and mplfinance.
How can I replace the line-charts to candlesticks charts with the hlines and scatter?I tried and produced 2 figures.

I did a chart by matplotlib with line-chart and entry point and exit point and TP/SL lines just like below,
image

the code:

plt.figure(figsize = (25, 8))
def trade_plot(df, trade, exit_price, exit_date):
    # df1=df[['Open','High','Low','Close']]
    # mpf.plot(df1,type='candle',mav=(30,100),block = False,returnfig = True)
    plt.plot(df['Close'][(trade['date_of_trade'] - timedelta(days = 100)): (trade['date_of_trade'] + timedelta(days = 30))], color = 'blue')
    plt.hlines(trade['TP'], xmin=trade['date_of_trade']-timedelta(minutes = 9),xmax=exit_date+timedelta(minutes = 9),color = 'green')
    plt.hlines(trade['SL'], xmin=trade['date_of_trade']-timedelta(minutes = 9),xmax=exit_date+timedelta(minutes = 9),color = 'red')
    if trade['signal']=='Sell':
        in_color='red'
        exit_color='green'
    elif trade['signal']=='Buy':
        in_color='green'
        exit_color='red'
    plt.scatter(trade['date_of_trade'], trade['entry_price'], color = in_color, s = 100)
    plt.scatter(exit_date, exit_price, color = exit_color, s = 100)
    return

plt.show()

and by the way, how can I set background black or dark mode?

I am so appreciated what you did.

@david03kimo david03kimo added the question Further information is requested label Jan 9, 2021
@DanielGoldfarb
Copy link
Collaborator

Hi David,

Thanks for your appreciation and interest in mplfinance. There are a number of mplfinance tutorials here that are each realtively short and should not take much of your time.

In particular I would sugest you focus on:

Within Customizing the Appearance of Plots you will probably be most interested in Mplfinance Styles regarding finding a style which has the dark background or dark mode that you want.

After reading the above items, it will be easier for me to answer any specific questions that you may still have.
Let me know. All the best. --Daniel


Click here to reference the mplfinance styles from which you can choose.

@david03kimo
Copy link
Author

david03kimo commented Jan 11, 2021

After reading the above items, it will be easier for me to answer any specific questions that you may still have.
Let me know. All the best. --Daniel

Hi,Daniel,

Thanks for your guiding.I have finished the graph mostly as below.It looks beautiful to me.
image

as to the parameter like matplotlib I cannot find it ,can you guide me?
plt.subplots_adjust(left=0.038,` bottom=0.038, right=0.98, top=0.96, wspace=0.17, hspace=0.17)

Thanks again for your help.
Cheers,

David

@DanielGoldfarb
Copy link
Collaborator

David,

That is a very nice looking plot. Thanks for sharing. I always enjoy seeing what people are doing with mplfinance.

Regarding subplots_adjust(), mplfinance does not have a specific adjust method or kwarg, however I think for your use-case you can use the scale_padding kwarg, which can take either a single value to adjust the padding all sides of the Figure, or can take a dict to adjust the padding individually on one or more of each of the four sides of the figure. Click here for information about using the scale_padding kwarg.

Please let me know if that works for you (or if you feel you need a better solution).

All the best. --Daniel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants