matplotlib / mplfinance

Financial Markets Data Visualization using Matplotlib
https://pypi.org/project/mplfinance/
Other
3.73k stars 636 forks source link

Problems with candles color and bg color #61

Closed MatteoSid closed 4 years ago

MatteoSid commented 4 years ago

I'm trying to make greyscale plots from a csv file, I need to have only 3 color in my images so I plot my graph like this:

mc = mpf.make_marketcolors(
    up='white',
    down='black',
    edge={'up':'white','down':'black'},
    wick={'up':'white','down':'black'},
    inherit=True
)
s  = mpf.make_mpf_style(base_mpf_style='classic', gridstyle = '', facecolor='grey', marketcolors=mc)

mpf.plot(df2,
        type = 'candle',
        style = s,
        title = '',
        ylabel = '',
        ylabel_lower = '',
        volume = False,
        show_nontrading=True,
        savefig = save_path + str(row) + flag
)

Then I delete all the edges with PIL and this is the result: 0_1 Apparently that's exactly what I wanted to get but zooming in we can see that the colors aren't correct.

Schermata 2020-03-22 alle 14 37 04

What would I have to do to get the uniform color in the candles? Thanks a lot.

DanielGoldfarb commented 4 years ago

@MatteoSid

Matteo,

Try setting alpha=1.0 in mpf.make_market_colors() That might work.

Also, please clarify what you mean by "Then I delete all the edges with PIL and this is the result:" Do you mean the axes edges (that's what it looks like in your picture; i just want to be sure I am understanding correctly).

Thanks. --Daniel

DanielGoldfarb commented 4 years ago

Btw, just because I am always trying to better understand the full breadth of mplfinance users and their use-cases ... and you posted a similar issue where you alos wanted to plot only the candles with no numbers axis edges, etc. ... can you help me understand your need/desire for such a plot?
What are you ultimately trying to accomplish, and/or what is the big picture of what you are using it for? Much appreciated.

MatteoSid commented 4 years ago

Try setting alpha=1.0 in mpf.make_market_colors() That might work.

Omg yeah, it's perfect!! Thank you so much for your help!!

Also, please clarify what you mean by "Then I delete all the edges with PIL and this is the result:" Do you mean the axes edges (that's what it looks like in your picture; i just want to be sure I am understanding correctly).

I only need to have the candles without the axes so I cut the edges of the image using Pillow

MatteoSid commented 4 years ago

Btw, just because I am always trying to better understand the full breadth of mplfinance users and their use-cases ... and you posted a similar issue where you alos wanted to plot only the candles with no numbers axis edges, etc. ... can you help me understand your need/desire for such a plot? What are you ultimately trying to accomplish, and/or what is the big picture of what you are using it for? Much appreciated.

I'm trying to create a Convolutional Neural Network to predict whether the next candle will be positive or negative. Convolutional Neural Networks extract features from images like edges or recurring patterns and since I just need to see the shapes that the graph assumes I don't need to have axes, I don't care about values. So, I decided to use grayscale images to get one channel images and then crop the image to remove the axes. This is the result: 4978_0

DanielGoldfarb commented 4 years ago

I'm trying to create a Convolutional Neural Network to predict whether the next candle will be positive or negative. Convolutional Neural Networks extract features from images like edges or recurring patterns and since I just need to see the shapes that the graph assumes I don't need to have axes, I don't care about values. So, I decided to use grayscale images to get one channel images and then crop the image to remove the axes.

Nice! Sounds very cool. I'd love to hear about your results. Please keep me posted. You can reach me at dgoldfarb.github@gmail.com or post here on GitHub. All the best.

bastulli commented 4 years ago

@MatteoSid Lol, I'm using it for the same application. CNN prediction with reinforcement learning. To convert the image to grey-scale just save the image to a buffer such asbuf = io.BytesIO()and use Pillow to convert to grey scale im = Image.open(buf).convert('LA')

DanielGoldfarb commented 4 years ago

@MatteoSid @bastulli

Matteo, Joseph -

Since both of you are doing similar work that requires a similar plot appearance, do either of you want to add it as an available style in the mplfinance package by adding a style file to the package, perhaps cneural.py or convneural.py?? --Daniel

MatteoSid commented 4 years ago

@MatteoSid @bastulli

Matteo, Joseph -

Since both of you are doing similar work that requires a similar plot appearance, do either of you want to add it as an available style in the mplfinance package by adding a style file to the package, perhaps cneural.py or convneural.py?? --Daniel

That would be great, but I don't know if it works yet. As far as I'm concerned, when I'm done, if it works, it can be done.

MatteoSid commented 4 years ago

@MatteoSid Lol, I'm using it for the same application. CNN prediction with reinforcement learning. To convert the image to grey-scale just save the image to a buffer such asbuf = io.BytesIO()and use Pillow to convert to grey scale im = Image.open(buf).convert('LA')

I'm just getting started. I have completed the creation of the dataset and the network model but for now the accuracy remains at 50%. Now I have to fix the HPharams to make the network learn better. If you want we can help, I'll leave you my email: matteo0593@gmail.com

Good luck for your work! ;)

miladd72 commented 2 years ago

@DanielGoldfarb It does not work for me

I also set alpha=1.0 in mpf.make_market_colors()

image

DanielGoldfarb commented 2 years ago

@miladd72 please show your code, and your data.

Are you making sure candle edges are same color, and/or erased?

miladd72 commented 2 years ago

@miladd72 please show your code, and your data.

Are you making sure candle edges are same color, and/or erased? @DanielGoldfarb thanks for your attention

mc = mpf.make_marketcolors( up='white', down='grey', edge={'up':'white','down':'grey'}, wick={'up':'white','down':'grey'}, inherit=True, alpha=1.0, ) s = mpf.make_mpf_style(base_mpf_style='classic', facecolor='black',figcolor='black', marketcolors=mc)

mpf.plot(df2, type='candle', volume=True, style=s , tight_layout=True, axisoff=True, scale_padding=0, savefig=r'C:\Users\Milad\Desktop\test5')

df2 is OHLC with volume from yahoo finance