-
Notifications
You must be signed in to change notification settings - Fork 653
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
Set single candle color #378
Comments
Fabio, In the meantime, there are two workarounds that I can think of: One is, as you said, import the old api from
df = pd.read_csv('../data/SP500_NOV2019_Hist.csv',index_col=0,parse_dates=True)
# Customize market colors, and place inside style you intend to use:
mc = mpf.make_marketcolors(up='yellow',down='yellow')
s = mpf.make_mpf_style(base_mpf_style='yahoo',marketcolors=mc)
# Create an all `nan` values dataframe, same size, and same index as the first:
nans = [float('nan')]*len(df)
cdf = pd.DataFrame(dict(Open=nans,High=nans,Low=nans,Close=nans),index=df.index)
# Copy in the specific candles that you want to color:
cdf.loc['2019-11-08'] = df.loc['2019-11-08']
cdf.loc['2019-11-15'] = df.loc['2019-11-15']
cdf.loc['2019-11-19'] = df.loc['2019-11-19']
# Call `mpf.plot()` twice with the two dataframes and two styles:
fig, axlist = mpf.plot(df,type='candle',style='yahoo',returnfig=True)
mpf.plot(cdf,type='candle',style=s,ax=axlist[0]) HTH. --Daniel P.S. I just noticed there is a slight discoloration in the yellow candles, due to the overlap with the red/green candles from the original dataframe. If this is a concern it can be avoided by replacing those candles with # Copy in the specific candles that you want to color, and replace them with `nan` values in the original dataframe:
cdf.loc['2019-11-08'] = df.loc['2019-11-08'].copy()
cdf.loc['2019-11-15'] = df.loc['2019-11-15'].copy()
cdf.loc['2019-11-19'] = df.loc['2019-11-19'].copy()
df.loc['2019-11-08'] = nans[0]
df.loc['2019-11-15'] = nans[0]
df.loc['2019-11-19'] = nans[0] |
@DanielGoldfarb Thanks a lot for the complete and exhaustive answer :) |
Hey @DanielGoldfarb ! I was facing the same issue and would like to contribute if that is okay :) Let me know if I can take this up and anything else I should know for coding this. |
@AurumnPegasus
Let me know what you think of the above, or if you want me to review and code in your fork. All the best. --Daniel |
Hey @DanielGoldfarb, Approach:
Remaining:
I need to just refactor my code and remove a fair few comments 😛 . If everything works out well I should be done by today! |
Shivansh, Yes, My concerns with how to implement are as follows ... and it seems you have already given this more thought that I have so, for now, I will trust your judgement and simply express my concerns: My first concern (obviously) is to keep the code as easily maintainable as we practically can. The other concern is this block of code here where users have the ability to specify up and down colors differently for the body, edge, and wick of the candles. So I am thinking that users specifying per-candle colors should also have that option. However they should also have the option to pass in simply a single color for each candle and the code would then use that color for all of body, edge and wick. The basic idea of this enhancement is that the user specified colors essentially override what Also, as I think about it, I find myself on the fence about the following: Should we force users to pass in a list of all colors and Nones, or list of all marketcolor dicts and Nones, but not allow mixing of plain colors and marketcolor dicts in the same list? Or should we allow such mixing? Obviously allowing mixing will make the mplfinance code a little bit more complex, but if we do as I first suggested: somewhere early in the code convert the entire list to markcolor objects, then this added complexity will be contained. Again, thank you so much for contributing. All the best. I am looking forward to reviewing and testing the code. Let me know if you have any questions. |
can i use a column of my csv with black, white and red to paint my candles with the color ? |
@brcake This is an interesting idea. Perhaps we can enhance mpfinance to accept a column name as the value |
Looking ad this, it seems like in the old API version you could set the color of a single candle, is there a way to do the same with the current version without using the function of the old version?? (i v already seen i could use the same function of the example by doing -> from mplfinance.original_flavor import candlestick_ohl)
The text was updated successfully, but these errors were encountered: