matplotlib / mplfinance

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

Feature Request: The line width argument adding request for 'candlestick_ohlc' about the 'Wick/shadow' part(above/blow line) #657

Open mic-user opened 5 months ago

mic-user commented 5 months ago

Is your feature request related to a problem? Please describe. Not a problem related. But new request.

Describe the solution you'd like Now we only can draw image We want to draw this as we want image

Describe alternatives you've considered I have edit the source file 'original_flavor.py' > the function '_candlestick' > manually edit the line width value within 'vline = Line2D(xx HERE xxx)' from '1' to 'what I want'

Additional context What if we can control the width by ratio or absolute number from any kind of argument style that flexible. Please.

DanielGoldfarb commented 5 months ago

@Mitchell-kw-Lee

Please take a look at the "widths" documentation for the new mplfinance api. Let me know if that allows you to do what you want. Alternatively propose the enhancement to apply to the new api.

Please note that original_flavor.py will be deprecated sometime this year, and no changes will be made, since all functionality provided by "original flavor" is also provided in the new api.

mic-user commented 5 months ago

@DanielGoldfarb .First of all, thanks for your guide. I'm afraid that cannot be actually archive my goal... I have wrote whole new code as below.

    df : DataFrame = pd.DataFrame.from_dict(data=_recordSet, orient='columns')
    df.index = pd.DatetimeIndex(df['date_at'])

    setup = dict(type='candle',volume=False,figscale=1.0)
    mc = mpf.make_marketcolors(up='red',down='blue', wick='inherit', edge='inherit')
    style = mpf.make_mpf_style(base_mpf_style='yahoo')
    mpf.plot(df,
                tight_layout=True,
                **setup,
                update_width_config=dict(candle_linewidth=4), 
                #scale_width_adjustment=dict(candle_linewidth=0.4), 
                style=style, 
                figratio = (1.5,2.0),
                savefig='testsave.png'
            )

It shows below that has an issue. image

The figure show the wick bolder than original 1pixel line. But It also enlarge candle body's border as well. What I'm looking for is that the way to enlarge the wick line only with no touch candle body's border. Is it archivable with current version of the mplfinance?

DanielGoldfarb commented 5 months ago

@Mitchell-kw-Lee It seems it's not currently possible. As you can see here the same line width parameter is used for the wick and for the edge of the candle body.

However this could be a somewhat easy change to mplfinance to have two separate width parameters. Inside the width_config we could simply add a new item, 'wick_linewidth', to be used independently from 'candle_linewidth' here.

We would have to take some care to be backwards compatible for those users who are already specifying 'candle_linewidth'. Seems to me the simplest way to do that is if 'wick_linewidth' is not specified, then 'candle_linewidth' applies to both (gets copied into 'wick_linewidth'), but if 'wick_linewidth' is specified by the caller, then 'candle_linewidth' and 'wick_linewidth' are used independently. This would be simplest.

Alternatively we could create a new width_adjuster_version ... 'v2' and in v2 not worry about backwards compatibility but always treat 'candle_linewidth' and 'wick_linewidth' independently.

What do you think?

mic-user commented 5 months ago

@DanielGoldfarb Thanks for the reply. By quick reading all of those are seems reasonable(I know you are the guru on this). So, 'wick_linewidth' would be great rather than making new interface. Would you please proceed and release the version which support 'wick_linewidth' sooner or later?

mic-user commented 5 months ago

@DanielGoldfarb Please don't miss the feature that setting color for 'wick_linewidth' as candle border color. Thank you.

DanielGoldfarb commented 5 months ago

@Mitchell-kw-Lee wick and edge color control is already available via mpf.make_marketcolors() See here: https://github.com/matplotlib/mplfinance/blob/master/examples/styles.ipynb

DanielGoldfarb commented 5 months ago

@Mitchell-kw-Lee Support for 'wick_linewidth' can happen sooner if you are willing to contribute code. I can certainly guide you through the process (if you are unfamiliar with the fork/clone/pull-request process) and will code-review and help test.

mic-user commented 5 months ago

@Mitchell-kw-Lee Support for 'wick_linewidth' can happen sooner if you are willing to contribute code. I can certainly guide you through the process (if you are unfamiliar with the fork/clone/pull-request process) and will code-review and help test.

@DanielGoldfarb I have no idea how to proceed it. If you want, let's do this quick. And there are following questions,

DanielGoldfarb commented 5 months ago

@Mitchell-kw-Lee

Sorry for the delayed reply. Please see https://github.com/matplotlib/mplfinance/blob/master/CONTRIBUTING.md#fork-clone-workflow and comments at the bottom there about coding standards.

Please take a shot at modifying the code according to my suggestions here and the above contributing guidelines. If you have any specific questions feel free to ask.

I recommend that once you have a clone on your local machine, assuming you are the only user on that machine, install mplfinance with pip install -e ./ (Do this from within the top level mplfinance directory.) This will install mplfinance directly from your clone, and create an "editable" install, meaning that any changes you make will be immediately reflected in the installed mplfinance on your machine (following a re-import). This makes development and testing easier since you won't have to re-install every time you make a change.

If you do share a machine with others (who also may be using mplfinance) then do the same as above but in a python virtual environnment so that only you see the version you are working on.

Let me know if you have any questions. Thanks. --Daniel