Skip to content
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

API for adding labels: mpf.make_addplot(..., label="myLabel") #605

Merged
merged 12 commits into from
Aug 1, 2023

Conversation

alexpvpmindustry
Copy link
Contributor

easy api for adding labels to mpf.make_addplot

image

Note:

  • use panel=1 to choose the lower panel
  • supported types: 'scatter', 'bar', 'line', 'step'
  • NOT supported types: 'ohlc', 'candles'

see examples/addplot_legends.ipynb for the example notebook.

courtesy of @ppseverin for inspiration, replacing PR #277

@alexpvpmindustry
Copy link
Contributor Author

possible solution to #276 #181

@DanielGoldfarb
Copy link
Collaborator

@alexpvpmindustry
Alex,
Just took a quick look. Beautiful job. I'm really swamped right now, but will do my best to set aside some time early next week (Monday or Tuesday) to fully test and then merge. In the meantime, please bump the version.
My mind is wondering (what do you think) should we rename the kwarg to legend_label to be more explicit (since there are also xlabel and ylabel and an annotation can have a label)? Or do you think it's self-explanatory as is?
All the best. --Daniel

@alexpvpmindustry
Copy link
Contributor Author

alexpvpmindustry commented Apr 11, 2023

kwarg to legend_label to be more explicit

I use matplotlib alot, so label would be the first thing I would try.

an annotation can have a label

That is new to me.

Either way, it would be more useful for the doc string to report all the allowed kwargs. Currently if I press shift+tab, the doc that comes out is quite useless.

some time early next week (Monday or Tuesday)

No worries mate, no rush on my side. Just happy to contribute

@DanielGoldfarb
Copy link
Collaborator

If you think 'label' is more intuitive for a matplotlib user that's ok. I know many of the matplotlib functions accept kwarg label meaning the label for the legend. Meanwhile, if you google "matplotlib label" most of the top results are about labeling the x and y axis. I don't feel strongly about this, but i do also want to be clear to users who may not be familiar with matplotlib. Part of my mplfinance philosophy is to make it easy to use without knowing matplotlib (or much python) while at the same time having hooks in place for those who know matplotlib and want to access it's full power.

Regarding doc strings, the is a method you can call, mpf.kwarg_help() which will output information about the kwargs (from the valid kwargs table). Perhaps I will add info about the kwarg_help() function to all of the doc strings.

@alexpvpmindustry
Copy link
Contributor Author

without knowing matplotlib (or much python)

sidenote: is there a way to provide kwargs suggestion/correction? like if someone input the wrong kwargs, the error at the end should say "ledgend_label" does not exist, do you mean "legend_label"? or something similar. in the docs of numpy functions, there is usually a suggestion for similar/related functions.

mpf.kwarg_help()

that is new to me :D

I will add info about the kwarg_help()

maybe u can put it into a todo.

@alexpvpmindustry
Copy link
Contributor Author

also, not sure if its somewhat related.
i think there should also be labels for mavs. maybe automatically generated or have the option to toggle it on or off or specify a list of strings.
but i realised mav was implemented all over the place, so might be a lot more difficult than doing legend_labels for make_addplot

@alexpvpmindustry
Copy link
Contributor Author

@DanielGoldfarb any updates?

@DanielGoldfarb
Copy link
Collaborator

Will try to look at this next week or the week after that.

@DrChandrakant
Copy link
Contributor

@DanielGoldfarb
i successfully attempted 'legend_label ' add add_plot

legend

legend 2

Following Merge PR Work Improve and creating New PR request Soon, any Suggestion for the new feature?

Script additions for 'ema' plotting #563

API for adding labels: mpf.make_addplot(..., label="myLabel") #605

@dempc6469
Copy link

checking in on the labes piece here. Any update?

@DrChandrakant
Copy link
Contributor

checking in on the labes piece here. Any update?

@dempc6469 That PR is Under review. If You Like That Concept Please Download the Source code from my mplfinance fork here: https://github.com/DrChandrakant/mplfinance/tree/mav_ytick_label

@dempc6469
Copy link

dempc6469 commented Jun 28, 2023 via email

@DanielGoldfarb
Copy link
Collaborator

@dempc6469 (et al)
I have a lot of mplfinance PRs to review. Unfortunately, this week, due to other pressing projects, I won't get to any of them. However I expect to begin reviewing mplfinance PRs again next week.

In the meantime if you do try out @DrChandrakant 's version I will greatly appreciate it if you can please post any feedback here. Thank you very much!

Copy link

@rudradesai200 rudradesai200 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this out and it works well. Can someone please merge this PR?

@DrChandrakant
Copy link
Contributor

I tried this out and it works well. Can someone please merge this PR?

I think the moderator is busy with other projects please download this and use link here alexpvpmindustry:master

@DanielGoldfarb
Copy link
Collaborator

Thanks to those who have tried this out!
I am hoping to get back to processing the backlog of PRs sometime next week.

@DanielGoldfarb
Copy link
Collaborator

DanielGoldfarb commented Aug 1, 2023

I've tweaked the code so that when passing a DataFrame to make_addplot() then it is possible to set label to a sequence of labels and each one will be used in order for each column of the dataframe that is plotted.

NEXT I need to test this new code for all relevant make_addplot() (i.e. line, bar, scatter) and also modify the addplot_legends.ipynb to have an example of doing this (as well as remove the part that suggest using multiple make_addplots instead).

I hope to finish this today or tomorrow.

@DanielGoldfarb DanielGoldfarb merged commit 50d7eb3 into matplotlib:master Aug 1, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants