mplfinance icon indicating copy to clipboard operation
mplfinance copied to clipboard

How to use make_addplot with a new y AND x axis?

Open Effysan opened this issue 2 years ago • 4 comments

I need to be able to place dots freely on top of a candlestick chart. How can this be achieved?

Effysan avatar Mar 29 '22 09:03 Effysan

The ability to have multiple y-axes, and the ability to place markers above, below, or around candles, is demonstrated clearly in the additional plots tutorial. Please take the 5 or 10 minutes needed to read through the entire tutorial.

(after reading through the entire addplot tutorial and trying that approach, then, for additional ideas, see this multiple scatter markers example and also issue https://github.com/matplotlib/mplfinance/issues/97.)


Time (the x-axis) is always shared between all panels.

If you really want to have multiple time axes in the same plot, you will have to gain access to the Figure and Axes objects and create your own Axes object that has a different time axis. If this is really what you want, please explain why; perhaps if I understand your final goal then I can suggest the best way to acheive that.

DanielGoldfarb avatar Mar 29 '22 10:03 DanielGoldfarb

Thank you for the fast and in-depth response Daniel.

I have indeed read the additional plots tutorial.

The use-case for my request is as follows: I am plotting a candlestick graph, with 2 moving averages displayed. I wish to mark every intersection of these 2 moving averages with a dot, which I am attempting to do by adding a scatter graph ontop of the candlestick graph, with make_addplot. Naturally, the points of intersection can appear at any x value. The issue is, of course, that I am not able to freely place markers/scatter dots on the graph. Any suggestion would be greatly appreciated(:

I will look into the suggesting "Gain access to the Figure and Axes objects". Thank you(:

PS. An additional question (that would also solve my problem): Is there a way to plot an individual market/dot at a single point, on top of a candlestick graph?

Effysan avatar Mar 30 '22 12:03 Effysan

OK. As I understand it now you want to be able to plot points for which the x-value is at any datetime on the x-axis, even if that datetime falls between two rows of you DataFrame (effectively interpolating between rows).

This can be done, but it can be quite tricky (for reasons that I will explain). A little too busy right now to provide the details. Hope to get back to you in a day or two.

DanielGoldfarb avatar Mar 31 '22 00:03 DanielGoldfarb

Exactly right!

No worries at all Daniel, thank you for this response.

Your time is clearly valuable, and I by no means expect your response to be a detailed walkthrough. A simple point in the right direction would be more than enough.

Thanks again(:

Effysan avatar Mar 31 '22 09:03 Effysan