-
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
how to add text to figure #60
Comments
presently there isn't a way to do this. we can possibly add a feature. Can you please give me a clear example or picture so that I can better understand what you want to accomplish? Thank you. |
wouldn't it be possible just to return the matplotlib figure reference so we can add our stuff without requiring additonal functions? would be so easy |
@jhmenke - That feature (set kwarg In the meantime, you can clone this repository to your local machine, and pip install from the repository (instead of from pypi) to be able to use that feature. Let me know if that works for you. |
Excellent, thanks |
That's what I was looking for (I hope). So I can use all matplotlib features (log scale, title, figsize...). |
Meanwhile you can already use plt.gcf().axes directly after the mpf.plot call to get the figure. |
Then you can do additional plotting, e.g.
|
I couldn't make it work...
|
I am not sure if figsize can be changed after the fact, but you can set figsize in the mpf.plot call mpf.plot(figratio=(10, 3)). You could try fig.suptitle("title") or plt.suptitle("title") You also forgot block=False |
In the same spirit, Now I must say it is easy to say what it should be when you do nothing. There may be many reasons I haven't see so don't feel bad, it is just my first reaction as a regular user of Matplotlib (I downloaded your lib an hour ago, and it seems to have a great potential). |
@jhmenke I couldn't make suptitle work. |
I just tried plt.title("new title") and it worked flawlessly. |
Yes, still doesn't work but that's not important if it will work with the
I use Jupyter which might be the reason?? |
I'm a little short on time, but will try to respond to as much of the above discussion as possible.
Now two points about the above: (1) even with customizations we generally want to provide an easy way for users to do the most common customizations without having to write a lot of matplotlib code (while providing the matplotlib expert with access to more detailed matplotlib functionality). AND (2) The second part of the above philosophy is still very much in development! You may have noticed that the description of the package says, New mplfinance package (to replace mpl-finance by mid 2020). ... In other words, a lot of what you are looking to do will be available, but possibly not until end of May or end of June for some of these features. If you would like to contribute coding skills to the project, some things may go faster. Note also, a very big step to providing more detailed matplotlib access will come when #17 is complete (estimate late April, early May). Now reagrding some of the above comments. I strongly recommend against grabbing the global Figure and Axes, and rather use Regarding defaulting to Regarding Regarding titles, and some other stuff mentioned above. It is clear that [some of] you have not read through the notebooks in the examples folder. You should do that, particularly customization and styles Finally, if you really prefer to do all the matplotlib work yourself, you may prefer to work with the old api: |
I actually just found this project a few days ago as I am switching from Java to Python. Awesome work @DanielGoldfarb! I too am looking for a way to add text to the chart, as I am quite new to using python/matplotlib I am a bit loss in how adding text would work when grabbing the axex from mplfinance. I see here that this is the way to add text to graphs. My question is, are the x axis in mplfinance numbers or dates? Also which axis am I suppose to grab from. From Daniels quote
I imagine that it is the first out of the list of axes so therefore ax1. Am I on the right track with this code, it doesn't seem to work...
Neither seem to work, I feel like with this api which is rather a simplified version of matplotlib which makes it quicker to plot charts, that I am mixing apples and oranges? |
@cvanolm It will be tricky adding text using the Figure and Axes returned by The main issue is that you need the x,y coordinates for where you want to place the text, and as you suspected the x-axis is not, most of the time, actually dates. For now, let's not even disuss 'renko' or 'pnf' (point and figure) plots, because both of those distort the x-axis to expand and contract time based on price movements. But for the other plot type (ohlc,candle,line) here is the issue: The default value for So to get the correct x-value for your text, you have two choices:
Regarding what the axes are that are returned:
I hope that helps. Maybe it even gives you enough to consider writing the code to build this into All the best. --Daniel |
Ideally, when we add this feature to
There is code that does exactly that, recently added to mplfinance for this enhancment. regarding |
Thanks a lot Daniel! It was rather easy to fix as I had just needed the arg of show_nontrading to display the text. For some reason I couldn't figure out the 1st method that you gave me regardless, I have it working. As for the API, I may be able to find some time to implement this text feature. I will clone the repo and start working on it. Is there any sort of protocol or style you'd like? I guess I can just make the add-text-to-chart function in a separate file for now to make it less confusing. |
@cvanolm Caelan, Please fork the repository first, then clone your fork. (If you are not familiar with the standard fork/clone/push/PR workflow, take a look at this). Try to follow, more-or-less, the style of coding that exists in The interface should be relatively simple. Perhaps a kwarg called The For implementation of the If you are unsure about any of this, take some time to read through the existing |
Cheers, yes I am actually new to GitHub but I do have experience with Git. I just read through the forking process and will start this weekend. I have read through quite a bit of the code already but will continue to do so. I also will try to follow the code style in mplfinance to keep it clean and simple for future users/devs. All the best, |
First, thank you for this fantastic library. Second: Is this text thingie implemented ?. |
@traderblakeq Presently in the middle of a low level enhancement to make the non-linear/discontinuous interpolation and extrapolation easier. Once that is done then this text enhancement will be relatively easy to implement. |
Hi,Denial:
thanks for your great work! and I want to know if there is a way to add a text to figure,thank you
The text was updated successfully, but these errors were encountered: