Comments (49)
Hi Daniel;
I think the ability to add a subplot or a custom indicator to the plot is extremely important, especially for algorithm developers. I create unique indicators all the time and not having a subplot ability would be quite detrimental. In fact, I found this thread after attempting to plot a variation of RSI with mplfinance
without success.
from mplfinance.
Hi Daniel, wonderful work, thanks so much. Just wanted to add some thoughts.
I second the need for adding additional subplots. Effectively I believe we all are trying to get to this view:
Seems like there are two approaches to consider:
- mplfinance owns figure/subplots and you can simply request to add another one below with new data to be plotted. This way you can continue applying all the magic behind the scenes to ease the usage of the library.
- mplfinance generates subplots of candlesticks etc. and returns them to the user who is responsible for embedding them in another figure. The pro here is that you can build more complicated figures that just happen to contain price charts.
I believe there is value in both modes, and they can coexist. Imho this feature is essential, I reckon very few traders make decisions based on price chart alone, or would go into trouble of programming to just display price chart with one indicator.
Good luck!
from mplfinance.
@krychu ,
I agree with you completely. Part 1 is almost done. You can see a tutorial for it here in my fork which I expect to merge into matplotlib/mplfiance master within a day or two. (Just finishing up some additional documentation and testing). All the best. --Daniel
from mplfinance.
+1 to be able to have access to the figure and axes outside of mpf, it is really important if you want to freely use matplotlib with the graphs (and who wouldn't want that?). Thank you :-)
from mplfinance.
double y-axis is now released. See the "additional plot" documentation here.
I am currently experimenting with a couple different ways of implementing subplots to see which is going to work the best.
from mplfinance.
@thatsblatzphemy ,
Thanks for you extended comments to give more perspective. As I mentioned in my original reply,
The ability to pass in your own Figure and Axes is definitely coming.
And although I stated here that the old API would be available "at least for the next several months" ... I have no intention of removing it until I have confidence that anything that could be done with the old api, can also be done with the new API.
Let me outline my current plan here, so you and others can comment. It sounds like, for you, a few enhancements to the old api would have been adequate, and I did, early on, consider that approach. However, based on feedback from others, and my own experience and frustration with the old API, I decided on the following philosphy:
mplfinance should be easy to use for someone who doesn't have the time to become a matplotlib expert, and in this regard handle about 90% of the most common use-cases of plots.
At the same time, it should provide hooks to allow matplotlib aficionados to customize their plots to more-or-less the same extent they could with the old API.
So you see the goal is to accomplish two approaches. There is no intention to replicate TradingView or anything like it. Rather simply to make the majority of use-cases very simple to achieve.
At present, it is the second part of the above philosophy that is only fractionally developed. Please note the description line at the top of the repository ... "New mplfinance package (to replace mpl-finance by mid 2020)." I am hoping to be there by June or so. This particular enhancement, the ability to create and pass in your own Figure and Axes, will go a long way to achieving the 2nd part of the philosophy of the new mplfinance.
I am glad you are gaining an appreciation for the complexity of maintaining this code. In order to make the API easy for the non-matplotlib-expert, the code does a lot of things internally that users otherwise have to do for themselves with the original_flavor.
Ideally I want to provide the ability for users to optionally pass in your own Figure and Axes, while maintaining the ability to not pass them in and have everything done for you (which many users very much appreciate).
In order to accomplish this, I expect to do a significant restructuring of code internally, and need to be careful not to break any existing functionality. (As a backup plan, we can always make a separate API for the "power users", similar to the original_flavor, but ideally I want to avoid that because it may mean a significant amount of duplicate code to maintain).
So here's the plan, and understand it stems largely from the fact that in order to accomplish the first, "easiness," part of the philosophy, the code needs and expects to have control over the FIgure and Axes; none-the-less, I am hopeful that the following plan will allow the API to optionally give up that control.
Forget what I said up here about mplfinance having its own methods for creating its own Figure and Axes for you to use. Instead, I expect to allow power users to use any matplotlib API they want to create their Figures and Axes (aka subplots), however there will be certain restrictions on how they are passed into mpf.plot()
mpf.plot()
will have anax=
kwarg to pass in any matplotlib Axes that you want, however you must also pass in the Figure that contains that Axes instance using thefig=
kwarg. (If you pass in a different Figure, one that does not contain your axes, thenmpf.plot()
won't know it, but behavior will be undefined, i.e. no guarantees).- If you specify the
ax=
kwarg when callingmpf.plot()
, and you also want to plot volume, then you must also pass in an Axes instance for the volume; so instead ofvolume=True
, you would sayvolume=my_axes_for_volume
where my_axes_for_volume is an instance of a matplotlib Axes (i.e. subplot). - Similarly, if you specify
ax=
formpf.plot()
then you must also specifyax=
for all calls tomake_addplot()
So that's my plan. It means that internally mpf.plot()
will have two modes: "external axes" mode, and "internal axes" mode. I am hopefuly that I will be able to do this, and fulfill the philosophy in total, but I won't know until I actually start coding. As always, I think I have thought through everything, but actual coding and testing often reveals unanticipate results (which usually can be overcome with a little extra effort).
All the best. Stay safe and healthy. --Daniel
from mplfinance.
Hi @DanielGoldfarb ,
Thanks for the great work you do, mplfinance is awesome!
I was wondering if it was possible to add panels to subplots? Basically I'm looking to create a grid of charts that each have one or two additional panels, to show custom indicators like Stochastic or MACD? I did see your "How to use your own matplotlib Figure and Axes in mplfinance" where you show 3 charts side by side with a volume panel below but those lower panels are quite a bit separated from the main panel with duplicated x-axis labels.
Here's an example of what I'm describing:
I've look around but can only find references to single charts which you already covered quite well in "Adding plots to the basic mplfinance plot()"
I think grid of charts would be quite invaluable for displaying multiple time frames as well as overviews of related stocks in sectors.
Thanks again!
from mplfinance.
@mablue see also https://github.com/matplotlib/mplfinance/blob/master/examples/external_axes.ipynb
from mplfinance.
This is the second request I've gotten for something like this, so will probably do something about it. There are some issues though. I'll describe here what I am thinking so that people can comment.
mplfinance.plot()
does a lot for you automatically. One of the aspects of the code, that allows mplfinance to do so, is that mplfinance.plot()
owns the Figure and all Axes. Passing in an Axes object would limit what plot()
can do, since it would then not own the Figure and Axes.
Also, passing in an Axes object would effectively make plot()
a lower level function, so that in order for plot()
to maintain its current capabilities, along with a more limited set of capabilities for the ax=Axes
case, the code would become needlessly complex, branching this way and that depending on whether the caller passed in an Axes instance or not.
I am inclined instead to create a new API, similar to plot()
but somewhat limited in its capabilities. I imagine something like this:
mpf.axplot(ax, df, type, upcolor, downcolor)
axplot()
would do the following:
- plot either 'ohlc' or 'candle' on the given Axes
- automatically format the date axis (hours/minutes versus months/years, etc).
- allow customization of up/down candle and ohlc colors
None of the other features of plot()
would be available to axplot()
-- no volume, no customization of appearance (other than up/down colors of candles and ohlc), no saving the plot as a file, etc. All of those things can be done by the caller, since the caller has already decided to write lower level code by instantiating and using instances of Figure and Axes.
I am also thinking maybe to restructure the code in such a way that plot()
would itself call axplot()
. If I can do that, it should make the code easier to maintain -- instead of having to maintain similar code in potentially two different places: both in plot()
and in axplot()
.
from mplfinance.
After your explanation I think it would be better to leave the plot()
method as is, to keep it's capabilities.
Maybe instead of creating a new api, just return the figure handle of the plot?
from mplfinance.
I will consider providing a keyword option to return the Figure
. There are potentially problems with this: by maintaining ownership of the Figure
and Axes
, mpf.plot()
is able to do a lot of stuff automatically for the caller. That is part of the philosophy behind mpf.plot()
being a "higher level" API compared with the old mpl-finance or the proposed axplot()
.
So if anything, for now, I will consider an option, maybe noshow=True
which means: (1) don't use context manager, (2) don't call plt.show()
, and (3) return Figure
. It is also almost certain at this point that mpf.axplot()
will be written; while it may not be the ideal solution for you, there are definitely others who have expressed an interest in such an API.
Please feel free, everyone, to continue this discussion. My ideal hope for mplfinance
is that it can make it easy for people to code 75% to 85% of the use-cases they have (and only slightly more complicated to code the rest). Contributing to these discussions is a great way to help us achieve that goal.
Also, please consider, just as a test/proof of concept, cloning the code and modifying it to return the Figure
and then, most importantly, please let me know if that works for you, or if perhaps you come up against another issue that we need to solve. If I know that it easily does for you want you want, that will weigh strongly in favor of me adding the feature to return the Figure
object. Thank you.
from mplfinance.
@verata-veritatis ... I just want to clarify a few things on my end, and then ask for some clarification as to what you want to see.
At present, via mpf.plot()
, there are two subplots available: the "main panel" that shows the OHLC bars/candlesticks, and the "lower panel" which can be used to display volume and/or other data. Please make sure you have read through the "additional plot" documentation to see how you can display your RSI indicator on the "lower panel".
As it is now, if you display both volume and an indicator on the lower panel, mpf.plot()
will automatically display the indicator on a secondary y-axis.
This feature will be enhanced for the next release of mplfinance
as follows: a secondary y-axis will be available for both the main and lower panel, and you will be able to specify for each addplot()
call whether you want to plot to be on the primary or secondary y-axis.
Now the question is, after reading the "additional plot" documentation are you able to display your RSI indicator? Is there something else you need (if so, what)? Do you have a specific need for more subplots(), and if so for what?
Here is my current thinking on additional subplots: If we implement mpf.axplot()
as described above, then you will be able to make as many subplots as you want, and have the freedom to organize them however you want. However it means you have to do a lot of the matplotlib work yourself to structure those plots. This situation won't be much different that the old api (for example, calling candlestick_ohlc()
).
We may also make one more subplot avabilable via mpf.plot()
(one more than the two that already exist, so a total of three subplots available) and perhaps allow two possible layouts for these subplots. Here are some pictures to clarify:
These two layouts are available now:
In addition we would make the following layouts available:
Please let me know if the two panel case (the one that exist now: see "additional plot" documentation) is adequate for what you want to do. If not, please explain clearly why it's not adequate.
Also, if the existing two panel case will not work, indicate whether or not you think the above proposal (of a few different layouts) or something similar would work. Thank you!
from mplfinance.
Hi Daniel,
Thanks for the effort. I personally would like to see if mpf have the ability to draw subplots. The reason: I need to draw candlestick for at least two timeframe( day and 30min), and a corresponding index candlestick.
from mplfinance.
@hbaaron please propose how you would want the mpf interface to look/work to do that. Thanks.
from mplfinance.
It will be greatly appreciated if many subplots are available in this lib.
One more question can we handle realtime tick by tick data updates in it?
from mplfinance.
... can we handle realtime tick by tick data updates in it?
please check this issue and confirm whether that covers what you are looking for.
from mplfinance.
Here is my current thinking regarding subplots: I did some experimenting with creating a Figure and subplots outside of mpf.plot()
and passing the subplot Axes objects into mpf.plot()
. The problem with that was that sometimes mpf.plot()
applied its style
and sometimes it didn't. It seemed that the style
was not applied to the first subplot but was (at least partially) to later subplots.
The issue keeps coming back to the idea that that mpf.plot()
does a lot for you, allowing you to write a lot less code than the old API, but it does so by taking advantage of the ownership it has over the Figure and Subplots.
So one possibility is to provide a "stripped down" version of mpf.plot()
, what I called mpf.axplot()
above, that would leave subplot creation, styling, some formatting, and a bunch of other things up to the caller, and would just do the basic OHLC Bars or Candlestick plotting for you. But it seems to me that's about the same as just calling the original APIs (for example, plot_day_summary_ohlc()
and candlestick_ohlc()
) so I don't think it's a good idea to just recreate that API.
Now I am thinking this: I could provide something like
fig = mpf.make_figure()
and
axes1 = mpf.make_subplot(figure=fig,<subplot_configuration1>)
axes2 = mpf.make_subplot(figure=fig,<subplot_configuration2>)
axes3 = mpf.make_subplot(figure=fig,<subplot_configuration3>)
axes4 = mpf.make_subplot(figure=fig,<subplot_configuration4>)
and these functions would return Figure and Axes as objects that are specific to, and owned by, mplfinance
.
Then the caller can pass these objects into
make_addplot(ax=subplotN)
and
mpf.plot(ax=subplot1,volume=subplot2,addplot=apd).
I plan to do some experimenting with this idea and see how it works out. I am in the middle of some other projects so it may take me some time. In the meantime ...
I would be very interest to hear from others what they think of this idea/this proposed interface for subplots. Also, if any of you have ideas or preferences for how you want the mplfinance
subplot interface to look and feel let me know. If no one has any preferences then I will just do something like what I have outlined here (assuming the experiments work out and I don't run into any snags).
Thank you all, and please continue to contribute your ideas and suggestions. And, of course, if any one wants to contribute coding skills that is also welcome.
from mplfinance.
... can we handle realtime tick by tick data updates in it?
please check this issue and confirm whether that covers what you are looking for.
It seems to cover the issue of realtime plotting, thanks very much, I will try it latter.
from mplfinance.
Here is my current thinking regarding subplots: I did some experimenting with creating a Figure and subplots outside of
mpf.plot()
and passing the subplot Axes objects intompf.plot()
. The problem with that was that sometimesmpf.plot()
applied itsstyle
and sometimes it didn't. It seemed that thestyle
was not applied to the first subplot but was (at least partially) to later subplots.The issue keeps coming back to the idea that that
mpf.plot()
does a lot for you, allowing you to write a lot less code than the old API, but it does so by taking advantage of the ownership it has over the Figure and Subplots.So one possibility is to provide a "stripped down" version of
mpf.plot()
, what I calledmpf.axplot()
above, that would leave subplot creation, styling, some formatting, and a bunch of other things up to the caller, and would just do the basic OHLC Bars or Candlestick plotting for you. But it seems to me that's about the same as just calling the original APIs (for example,plot_day_summary_ohlc()
andcandlestick_ohlc()
) so I don't think it's a good idea to just recreate that API.Now I am thinking this: I could provide something like
fig = mpf.make_figure()
and
axes1 = mpf.make_subplot(figure=fig,<subplot_configuration1>) axes2 = mpf.make_subplot(figure=fig,<subplot_configuration2>) axes3 = mpf.make_subplot(figure=fig,<subplot_configuration3>) axes4 = mpf.make_subplot(figure=fig,<subplot_configuration4>)
and these functions would return Figure and Axes as objects that are specific to, and owned by,
mplfinance
.Then the caller can pass these objects into
make_addplot(ax=subplotN)
and
mpf.plot(ax=subplot1,volume=subplot2,addplot=apd).
I plan to do some experimenting with this idea and see how it works out. I am in the middle of some other projects so it may take me some time. In the meantime ...
I would be very interest to hear from others what they think of this idea/this proposed interface for subplots. Also, if any of you have ideas or preferences for how you want the
mplfinance
subplot interface to look and feel let me know. If no one has any preferences then I will just do something like what I have outlined here (assuming the experiments work out and I don't run into any snags).Thank you all, and please continue to contribute your ideas and suggestions. And, of course, if any one wants to contribute coding skills that is also welcome.
Thanks for the awesome job, I think returning a figure would also a good improvement.
from mplfinance.
I have found that mplfinance to be a great benefit in it's simplication and reduction of the work required.
That being said an ability to extend beyond the current limit of two subplots would be greatly appreciated.
If the code is extended to add a third (or more) subplot, with mplfinance retaining it's control and feature set, that would seem to be a superior solution.
The above solution works, as well as, the previous suggestion to add a "third" subplot window.
from mplfinance.
Hi Daniel;
I think the ability to add a subplot or a custom indicator to the plot is extremely important, especially for algorithm developers. I create unique indicators all the time and not having a subplot ability would be quite detrimental. In fact, I found this thread after attempting to plot a variation of RSI with
mplfinance
without success.
Hello Daniel. Thank you for all the hard work.
I hope you'll accept my input with a grain of salt. I only learned what a command prompt was a month or so ago.
I have came a long way. Only to finally get hung up for multiple days on this exact concept from OP I quoted here.
I cannot plot an RSI in mplfinance. I am developing an algo, and as OP suggested... highly detrimental to the cause.
IMO, the mpf function simply cannot control the figure. I tried multiple things ... like attempting to call the mpf function individually from within a ax2 or the like subplot, but to no avail.
I keep envisioning calling an instance of the mpf function individually within an axes subplot call is the solution. But of course, I have absolutely no idea what I'm talking about.
The only real necessity of this program IMO is to leverage the customizations of matplotlib itself. We really just need the candle visualizations. And infact, the only reason I kept trying this way instead of using old flavour was because I really just wanted to be able change the borders and wicks color of my candle bodies.
So your mpf function IMO severely limits the real world application of this package. I think you should ditch it entirely. Leave the customization upto the individual to control themselves with the RCPARAMS sheet, and matplotlib styles.
Ditch the MPLFinance styles. Irrelevent and un needed.
This is the way.
Thank you so much!!!
from mplfinance.
@thatsblatzphemy
Thanks for your input. Definitely appreciated! And it appears to me (based on your suggestions and how clearly you've expressed them) that having "only learned what a command prompt was a month or so ago"
is not a factor in this dicussion.
That said, you appear to have some misconceptions about mplfinance and what you can presently do with it: You absolutely can plot RSI as the package exists now. Let me quote from my reply, to the comment from which you quoted "I think the ability to add a subplot ...". And please note that my reply asks a couple of questions at the end, for which I still have as yet to receive an answer:
At present, via mpf.plot(), there are two subplots available: the "main panel" that shows the OHLC bars/candlesticks, and the "lower panel" which can be used to display volume and/or other data. Please make sure you have read through the "additional plot" documentation to see how you can display your RSI indicator on the "lower panel".
Now the question is, after reading the "additional plot" documentation are you able to display your RSI indicator? Is there something else you need (if so, what)? Do you have a specific need for more subplots(), and if so for what?
- If you can please actually use
make_addplot()
to plot RSI, and then answer the above questions, that would be very helpful.
Now, to clear up a couple of the other misconceptions in your comments:
-
A regular matplotlib style (rcparams) does not allow you to control the candlestick and ohlc bar colors. That is the main purpose of an mpf_style. It is simply a combination of the "market colors" and matplotlib styles (rcparams). Nothing more really. And you can still do everything you want to with rcparams.
-
If you want full and complete matplotlib control over everything (and the work associated with that) then you are free to use the old API for which you can find examples here, and documentation here.
-
The ability to pass in your own Figure and Axes is definitely coming. That's why I'm keeping this issue open, and have labeled it "enhancement." I am also fairly certain that I won't actually need to do as I outlined above (having mplfinance create and maintain ownership of the Figure and Axes), but I have a few more tests to run to make sure it does not break any of the advantages that mplfinance provides over the old API.
-
If you do have experience working with the old API, and with the new API, then you know how much extra work the old API required. For someone well versed and experienced in matplotlib, that's not a big deal. That's why the old API is still available in this package. But a very large number of users are less interested in becoming matplotlib experts and more interested in focusing on the visual analysis of their data. The new API allows them to do that.
Again, it would be greatly appreciated if you could take the time to use the addplot functionality for RSI, or whatever other technical studies you would like to add, and then send me feedback.
All the best. Stay safe and healthy. --Daniel
from mplfinance.
Looks like returnfig has been implemented as an argument in the master branch of this repo. That should accomplish what has been discussed here. Any idea when you will release it to PyPi?
Thank you!
from mplfinance.
Correct, returnfig
has been implemented. But it will accomplish only a small part of what is discussed here. (try it and see). Nonetheless, it will help.
I am keeping this current issue open in expectation of implementing the ability to create your own Figures and Axes and pass them into mpf.plot()
.
Regarding the next release: Issue 67 is being used to track the next Pypi release. There will be 6 items included in that release, and as you can see from the list there, three items are "merged and awaiting release" and three are "in progress". I am hoping the release will be ready by the end of next week.
In the meantime, if you would like to play with returnfig
or any of the other "merged and awaiting release" items, you can install it as follows:
git clone [email protected]:matplotlib/mplfinance.git
cd
into the main mplfinance directory of the repository (the one that contains setup.py)pip install . <enter>
# Notice the dot '.' inpip install .
HTH
from mplfinance.
Hey Daniel, thanks for the quick reply, and apoligies for not responding sooner!
So, for my particular case, I do use a few other indicators other than simply RSI. As well as sometimes multiple RSI's (ie stochastics).
I was aware could plot my RSI on the lower panel. But I my goal was to design all my panels (ax's) and indicators and have everything dialed in the first time.
I played out multiple scenarios to achieve my needs with mpf.plot, including running a seperate script for each indicator lower panel with adplotdicts.... quickly realizing that would be highly inefficient. For the record, I am a pro+ subscriber on Trading View, and I know exactly what I want and need and how to builld it up.
To think my account there is nearly obsolete when I didn't think any of this was possible just a few months ago is exciting and mind boggling.
Back to the issue at hand ... and please accept everything I say as mere thoughts as an observer without all of the information. I am starting to have some kind of an idea the amount of work and complexity involved in maintaining this whole thing, and appreciate all you're doing.
That being said ... I don't think you should waste any time attempting to replicate TradingView or what it is. Each person can be the TradingView. TradingView still has it's purposes and benefits IMO. You can practice and learn how to use indicators there ... programming indicators from scratch is no way for a beginner to learn how to use them. They have to be easy. If you think they have merit, then learn the code.. build the bot ... and here I am.
"Now, to clear up a couple of the other misconceptions in your comments:
A regular matplotlib style (rcparams) does not allow you to control the candlestick and ohlc bar colors. That is the main purpose of an mpf_style. It is simply"
EXACTLY !!! IMO, this is all mplFinance needs to be ... candlestick, and OHLC, and renko ... and any other form of candle stick type addition to a graph. ...Ideally with the ability to change candle edge and bodies seperately (new flavour) but maintaining functionality of the Old flavour.
I feel like new flavour offered nearly 0 functionality for me.
For the record, my price chart is not my main chart ... my candles are on what would be considered the lower panel (however still on top) in mpf.plot and my main indicators occupy an area greater than the main panel. I am all indicator. I don't even really need price action. And the truth is ... I don't technically need the candles either to continue on with my algo. I just want to see them.
And here is where I am sure I don't understand the complexities fully , because I simply envision a solution where mpf.plot only affects 1 subplot instance of ax .... I mean ... again, what is the purpuse of mplFinance?? Candlesticks(or the like). I would really hate to see all this work go into something and for it to be less functional , and likewise, I'd hate to see you do more work than you need to !
I think matplotlib needs to be leveraged as much as possilbe. They have style sheets now. They look good out of the box. Also the freedom to choose subplot, subplot2grid, gridspec; is important to some I think.
Is it in no way possible to simply call the mpf plot that will contain the candles; using a simple subplot ax(n) ???
That subplot could still be a (1,1,1) where it takes up the whole fig if other indicators are not needed no???
You could still add the volume as a seperate subplot that simply fully overlaps the main subplot in the grid(if using gspec) ... no??
So Volume NEEDING to be on the chart with candles is not paramount IMO.
And again ... I think most importantly, mplFinance is not looking to replace TradingView, and it you shouldn't be too focused on developing any of that functionality imo. Just candles (and the like) in matplotlib! I know I'm sure Im oversimplifying. But again, more work for less functionality it seems to me. But if I am customizing matplotlib myself as a complete noob ... everyone else can figure it out too.
So atm, I am using old flavour, so please don't disontinue that! I'm really not sure where I could be any more help. But I am more than welcome to offer some input, also interested to hear back from you. Cheers.
from mplfinance.
I'll be honest ... I think you understand the situation better than I do!
And the way it sounds when I read it makes me think it will infact be the best of all worlds for everyone once complete.
Great things do take time, and I look forward to using the finished product. And of course, supporting its existence once I make it big here after I turn this thing on.
I'm not sure If i'd classify a 'power user' or not, but if all I had were candles with seperate colours up and down (AND edge/wick and body). I would be more than happy and IMO you could put a stamp on 'er and call 'er good!
Cheers and keep up the good work.
from mplfinance.
if all I had were candles with seperate colours up and down (AND edge/wick and body). I would be more than happy
If you want to take a shot at adding edge and wick colors yourself to the original_flavor API, feel free. It should just be a matter of adding maybe edgeup
, edgedown
, and wickup
and wickdown
to the args for candlestick_ohlc and the function that it calls _candlestick() and then using them appropriately here and here.
from mplfinance.
from mplfinance.
There are no kwargs for that in the original flavor API. Instead, you use the "2" versions of the APIs, for example: https://github.com/matplotlib/mplfinance/blob/master/src/mplfinance/original_flavor.py#L555 and https://github.com/matplotlib/mplfinance/blob/master/src/mplfinance/original_flavor.py#L411
The way it works (in both the original flavor and the new) is by using a range of integers (instead of dates) along the x-axis. Then, if you want to display dates, you have to write your own date formatter to translate the integers to formatted dates. (The new API does that internally. With the orignal you have to do it yourself). If you are unsure how to do that, take a look at the way the new API does it here: https://github.com/matplotlib/mplfinance/blob/master/src/mplfinance/plotting.py#L253-L258 and here: https://github.com/matplotlib/mplfinance/blob/master/src/mplfinance/_utils.py#L450-L485
All the best. --Daniel
from mplfinance.
from mplfinance.
Daniel,
Thank you very much for mplfinance.
I'm new to matplotlib, I started using gnuplot 18 years ago and... yeah, I wish I had moved before! :-(
In gnuplot I use at least 6 panels, so addplot is not an option. I guess that the old api is ok for me. Harder work? I suppose that I can handle it, as long as everything is well documented. And your help in github, cherry on the cake!
The only problem I see is that it seems that old API might disappear in the future. So perphaps the library could have 2 APIs:
- Old one, for low-level control. So it would be not "deprecated" but "low level"
- New one, to make basic things straightforward
from mplfinance.
from mplfinance.
ok, thank you, I have read this thread again and I see that my question is already answerd: there will be a way to manage several axes, what Daniel calls "external axes". But with a new low level API, because maintaining old API would be a not reasonable effort.
Please apologize my post, it was not needed. Even though I think that would be a good idea that main documentation warns about this : there will be a new low level api, if you need access to axes, use old one meanwhile.
Again, thank you all.
from mplfinance.
from mplfinance.
Hi Daniel, first of all I wanted to thank you for your great effort.
I'm curious, can the 'lower' part of the plot include a bar chart? I know logically it should because the volume is a bar chart as well. I'm fairly new at using python so my logic could be flawed.
I read the "additional plot" documentation and I couldn't find any mention of the plot types it accepts (and how to do it).
The reason I am asking: I wanted to plot a MACD with its histogram in the lower section by turning the volume bars off, while keeping the stock price in the main.
I managed to plot the MACD, but not its histogram because I couldn't tell how to make the lower section include a bar chart.
from mplfinance.
I read the "additional plot" documentation and I couldn't find any mention of the plot types it accepts (and how to do it).
@Faisal-gr ... You are correct in thinking that mpf.make_addplot()
should be the way to do it, however presently make_addplot()
assumes a line plot, or if scatter=True
then a scatter plot.
In theory we could add a plot_type=[line|scatter|bar]
to mpf.make_addplot()
. If you want, take a look at the code and see how you might do that. Aside from allowing make_addplot()
able to accept plot_type
kwarg, the actually implementation of the bar chart would be within the "addplot" section of the mpf.plot()
in file plotting.py
Let me know if you are interested in getting involved and I can advise. Otherwise I can put it on the list of things to do and it will get done eventually.
A kludge/work-around, in the meantime, might be to pass your MACD histogram in as a column of your dataframe named 'Volume' and set Volume=True.
from mplfinance.
@DanielGoldfarb Thank you very much for your timely response. I appreciate the work-around suggestion; I will certainly try to use that and see how it pans out until a future update is rolled out.
Regarding the code, my experience is very limited as I'm only 1 week into coding although I came a long way given the short time frame, but I will definitely take a look at it. If anything, it will give me an appreciation of the work done 'behind the scenes'.
Thanks again and I appreciate you considering it in future updates.
from mplfinance.
Just read through it, this is fantastic @DanielGoldfarb. Thank you.
Another thought that came to mind: is the distinction between main and additional plots necessary? An option would be to have .plot([ds1, ds2, ds3], ...)
. ohlc and volume charts would be created just like any other chart with make_addplot
. This way you could have multiple ohlc charts in one figure. Just a thought.
from mplfinance.
I agree. And there is a plan to allow any chart type on any panel; I want it to to seem that simple to the user. But under the hood it will require a significant restructuring of the code, so I am taking time to do it step-by-step to avoid breaking any existing functionality.
The need to restructure the code is partly historical, but mostly because, what is not always apparent to the user is that, mplfinance does a lot of stuff for you automatically to try to make things easier. This requires handling different plot types somewhat differently from each other. For example, handling up/down colors, styles, etc. There is also an algorithm (improved with the next version) that adjusts candle widths and wicks to look good over a variety of data patterns. (Candle widths that look good with one data set may not look good with another. The old mplfinance required the user to make adjustments like that themselves.) Even plotting volume is not the same as plotting a simple bar chart with addplot
. And there are differences for the renko and point and figure charts as well.
All this is to say it can be done, but it will take some time. One of the "disadvantages" of abstracting away all the work, is that it can become difficult to appreciate just how much is being done to achieve that abstraction (unless, of course, you've used the previous package where you had to do all that work yourself).
Again, thanks for your input. And if you'd like to share some of the plots you've made that would be very much appreciated. It's nice to see some of the creative things people are doing with this package.
All the best. --Daniel
from mplfinance.
Thanks @DanielGoldfarb
I can imagine this being a major restructure as it changes the fundamental model of the API. But I'm glad it's on your roadmap.
As a user I fully appreciate the difficulty of hiding all the complexities and know it requires a lot of work. I also believe financial domain is where it will work well because there is a strong use-case and understanding of what the final chart should be.
Once I have something reasonable I'll send your way. Sorry for diverging in this issue but wanted to throw few things that would be useful (perhaps they are already supported in which case apologies):
- filled bands
- drawing vertical lines spanning all stacked charts (probably hard to implement)
- drawing arbitrary lines, and filled rectangles (without left and right borders)
Thanks again and good luck!
from mplfinance.
- filled bands is now possible, using the fill_between kwarg (presently only supported for the "main" panel)
- vertical lines are available, but also presently only supported for the main panel. probably not too difficult to have a vertical line drawn for all panels, since as they are now they all share the same x-axis.
- arbitrary lines also available now, but again only for main panel presently.
- lines documentation here
- not sure what you are getting at with filled rectangles. what are you trying to accomplish from a financial visualization perspective?
I am going to close this issue. However we can continue the discussion here on the closed issue to sort out exactly what you are looking for.
I am only closing it because I want each issue to represent one feature request or one bug. I have implemented a limited form of subplots, as described here as the "Panels Method".
I am planning to implement a more general form of subplots as described here as "The Matplotlib Method". I will open a separate Issue to track that feature request.
Ultimately I would love to get mplfinance to a point where it can, in a relatively easy-to-do way, make a plot similar to this in all its glory (including all of the labels, colors, and annotations) but that will take some time ... less time if others contribute, but time none-the-less.
from mplfinance.
My existing plots directly use matPlotLib I want to add candle sticks to those graphs not have the candle stick take over. In the old api at mpl_finance it worked great I just passed in the axis of my existing work. You really should support the old strategy. I will just use the deprecated version until you do.
from mplfinance.
@joeatbayes
Joe, by the way, not sure if you noticed, but even though the old package is deprecated, the old api is still available within the new mplfinance
package. See here: https://github.com/matplotlib/mplfinance#oldapi HTH. --Daniel
from mplfinance.
How can I put a few marker on candle chart like as Moving Average
marker position is random position which I want to mark it.
from mplfinance.
@usimjo
Please take 15 minutes of your time to carefully read these tutorials:
- https://github.com/matplotlib/mplfinance#usage
- https://github.com/matplotlib/mplfinance/blob/master/examples/addplot.ipynb
Please also see the list of tutorials here:
Let me know if you have any other questions after that.
All the best. --Daniel
from mplfinance.
Hi @DanielGoldfarb , Thanks for the great work you do, mplfinance is awesome! I was wondering if it was possible to add panels to subplots? Basically I'm looking to create a grid of charts that each have one or two additional panels, to show custom indicators like Stochastic or MACD? I did see your "How to use your own matplotlib Figure and Axes in mplfinance" where you show 3 charts side by side with a volume panel below but those lower panels are quite a bit separated from the main panel with duplicated x-axis labels.
Here's an example of what I'm describing:
I've look around but can only find references to single charts which you already covered quite well in "Adding plots to the basic mplfinance plot()"
I think grid of charts would be quite invaluable for displaying multiple time frames as well as overviews of related stocks in sectors.
Thanks again!
I really want to know how you do that?!
from mplfinance.
Please anyone can tell ,There is any simpler way to change volume panel from bar type to line or something else
from mplfinance.
@hellovikas
The simplest way to make volume a line-plot (or anything other than a bar plot) is to use mpf.make_addplot()
to plot the volume. You will, of course in that case, not set the volume
kwarg at all.
I suggest you read through these two tutorials first:
I strongly recommend that you do not use the external axes method this is being discussed in this issue above.
If you have any questions, after reading through the above two tutorials, then let me know.
from mplfinance.
@hellovikas The simplest way to make volume a line-plot (or anything other than a bar plot) is to use
mpf.make_addplot()
to plot the volume. You will, of course in that case, not set thevolume
kwarg at all.I suggest you read through these two tutorials first:
I strongly recommend that you do not use the external axes method this is being discussed in this issue above.
If you have any questions, after reading through the above two tutorials, then let me know.
Thnx Sir i have achieved by make_addplot plot rather than using volume to true
from mplfinance.
Related Issues (20)
- I just don't know who to ask…. HOT 1
- mplfinance warn if user passes an empty data set. HOT 1
- Feature Request: The line width argument adding request for 'candlestick_ohlc' about the 'Wick/shadow' part(above/blow line) HOT 9
- Bug Report: marketcolors display error when open=close HOT 1
- Bug Report: Typo HOT 1
- How do I create a buy indicator using mplfinance? HOT 1
- Using with `matplotlib.testing.decorators.image_comparison` HOT 6
- PNF ATR Boxsize HOT 4
- Hollow and Filled Candles HOT 1
- Feature Request: Add SubFigures to Mpf_Figure HOT 2
- The example image of price-movement_plots.ipynb is inconsistent with the displayed result. HOT 3
- Interactive plots for OHLC candles with mplfinance HOT 1
- What is the most elegant way to implement ribbons? HOT 4
- Bug Report: legends on panels overlaps
- PnF Reversal Bug
- Bug Report: Errors occur for NaN columns.
- The use of `returnfig=True` creates multiple figures when using ipywidgets
- Custom Candlestick Timeframe HOT 2
- Bug Report: Inconsistent Volume Bar Border Colors Between v0.12.9b7 and v0.12.10b0 When Using make_marketcolors
- missing from current font. FigureCanvasAgg.draw(self)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mplfinance.