-
Notifications
You must be signed in to change notification settings - Fork 634
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: Alternative method to calculate bar widths #115
Comments
Can you please provide the data and code you used to make these plots. I want to be able to reproduce on my own system to better understand. Thank you. |
Hi, Here is the sample code. Please note that the difference might not be visible if your monitor resolution is high. My monitor resolution is 1920x1080. Running As you can see the volume bars on the left has non-uniform widths, while the one on the right looks more uniform. I have only changed the bar widths on the volume bars. The same method can be implemented to the candle bars. There is a problem when implementing this with the candles though, since the edge is used as a padding, when the value of |
@char101 Charles, |
@char101 Your widths look nice on your chart. I found that the same widths may or may not look nice depending primarily on three things: (1) how much data there is, (2) how far apart the data is (intraday, daily, weekly, etc) and (3) whether or not I've come up with an algorithm that automatically adjusts the volume widths and candle widths for all of these things. I expect to enter a PR for it sometime in the next couple of days. If you want to test it, it is presently in my fork (please just keep in mind I will be making other changes to that code before the PR). Thanks. --Daniel |
Thank you Daniel for you work on this. |
Charles, by the way, thanks for the excellent code here that quickly compares the two versions. When I was first developing my algorithm, I included it in that code as a third version to compare. |
Thanks Daniel, glad that it could help a little. |
@char101 Thanks for bringing this up. Just curious about how did you put the volume labels on right and price labels on the left in Y-axis. And how did you configure the volume label to be '10m', '20m' instead of default multipliers I get like 'x1e7'? |
This sounds perfect, Daniel. I did some digging around the code and was thinking of something in the similar line. But if you have already done it, I'll wait for that. Also I have faced another issue with candlestick wicks where the wicks looks like weird blotches when there are quiet a few candles, like the image below. After some digging around, looked like this is related to anti-aliasing and after I enabled AA, it looks like below. Which is what I was looking for. The candles look a bit blurred with AA enabled but I prefer that over the blotched ones. Let me know if this is something you want to incorporate then I can create a PR. Added it as a completely optional parameter which does not change the default behavior. Note: The second image has a few more changes than just AA. However, the changes in candle appearance is solely due to enabling AA.
Thanks for maintaining this awesome module! |
To move label position: To customize the label you need to set your own label formatter |
@Atekihcan ,
Have you tried the new code in my fork? The automatic candle width adjustment adjust wicks also (and the volume bars). I know I mentioned above, over two weeks ago, that the PR to bring in the new self-adjusting code would be in a few days, however due to unforseen circumstances, unrelated to this project, that was delayed. Hopefully next week. In the meantime, if you want, you can install the code from my fork. The code is ready; I am just putting the finishing touches on the documentation for the new features. If you do get a chance to test the new code, please let me know if it works for you. I suspect you will find the automatic adjustments adequate (for candles, wicks, and volume bars) and will not need to include any code (AA or otherwise) outside of mplfinance; but let me know. Also, fyi, the new code includes kwarg Also, with the existing release, v0.12.4a0, you already can control whether the y-axis is on the left or right using styles by setting kwarg |
Thanks for the suggestion. Your changes work well enough. No need to tinker with AA or otherwise.
Awesome! 👍
Yes. This I was aware of. I wanted to know how to put price label on the right and volume label on the left. |
Thanks for beta testing the code. Much appreciated and thanks for the feedback. Regarding Regarding the wicks sometimes being off center, this will probably take a good amount of investigation. Your guess as to reason(s) behind this phenomenon seem to me to be a good place to start an investigation. As you saw, the width-adjustment algorithm uses a heuristic approach, since it is extremely difficult to determine exactly how the appearance of the various plot elements will be affected by the input data and selected options. I simply spent a full day playing with a lot of different data sets, and a lot of different width and linewidth settings, eye-balling what I thought looked "pretty good" on my screen. You may have noticed that I have provided a
Hmm. Perhaps in a future version we can allow left/right label control on a per-panel basis. All the best. --Daniel |
No problem 👍
It'd be great if it can be made default. There is no issues with plots in notebook, with getting the axes list and doing it myself. But that doesn't work if I'm saving the figure as the figure is saved before I'm doing that.
Yeah, it depends a lot on many other factors like DPI, screen resolution, figure size etc. If I get some time, I'll see if I can spend some time on it. |
new version 0.12.5 just released to Pypi has new algorithm for calculating widths of candles, wicks, volume bars, and ohlc bars and ticks. |
Is your feature request related to a problem? Please describe.
In small charts, the volume bar (and maybe the candlestick bars too) are uneven because of the rounding of the fractional width values of the bars.
Describe the solution you'd like
Alternatively I have modified it to use bar width = 1, and then adding edgecolors='the color of the background' (actually I just set it to 'k' because I'm using a dark style) and linewidth=1 for the volume panel. In my opinion the result looks better. The bar widths are still not uniform but the spacing looks uniform.
The text was updated successfully, but these errors were encountered: