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

Added labels for make_addplot function (lines,bars,scatter). Missing …for _mscatter function. #277

Closed
wants to merge 1 commit into from

Conversation

ppseverin
Copy link

Its missing for the _mscatter function. I didn't understood very well the function (maybe if I spent more time on it I could). Tested on jupyter lab and worked fine. Hope this is useful for the community. :)

Copy link
Collaborator

@DanielGoldfarb DanielGoldfarb left a comment

Choose a reason for hiding this comment

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

  • See also individual comments in the code below.

Here is a more general comment:

I did some testing with the addplot notebook, adding a labels= kwarg to several of the examples in that notebook. It appears that Axes.legend(labels=labels) requires that labels be an iterable (list or tuple) of labels. If I pass a single string, it gets treated as a list of 1 character labels (since a string object is iterable).

However I do like the idea of allowing mplfinance users to pass a single string (rather than forcing them to pass a len=1 tuple such as labels=('my label',), which I had to do in order to get the code to work as expected for the case of a single label).

Therefore I would suggest that, perhaps somewhere near line 772 (aptype = apdict['type']) we could insert:

labels=apdict['labels']
if isinstance(labels,str):
    labels = [labels] # convert to list

Then in all subsequent code below that, only need to use the variable labels (and no need to again reference apdict['labels']).

if config['title'] is not None:
if config['tight_layout']:
# IMPORTANT: 0.89 is based on the top of the top panel
# being at 0.18+0.7 = 0.88. See _panels.py
# If the value changes there, then it needs to change here.
title_kwargs = dict(size='x-large',weight='semibold', va='bottom', y=0.89)
Copy link
Collaborator

@DanielGoldfarb DanielGoldfarb Oct 19, 2020

Choose a reason for hiding this comment

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

It appears that this section was removed. I'm guessing that you did not do this on purpose, but rather made your changes to a version of the repository that was cloned before August 16, 2020 (when this enhancement was merged into the repository). A more recent version of the repository should be merged into this pull request (or, alternatively, these changes can be applied to a more recent clone of the repository, and then push that clone into the fork that is the basis for this PR).

If you have any questions about this, please let me know

def _label_validator(label_value):
if isinstance(label_value,str):
return True
elif not isinstance(label_value,tuple) and not isinstance(label_value,list):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be simplified:

elif not isinstance(label_value,tuple) and not isinstance(label_value,list):

becomes

elif not isinstance(label_value,(tuple,list)):

else:
ax.scatter(xdates,ydata,s=size,marker=mark,color=color,alpha=alpha)
if apdict["labels"] is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since apdict["labels"] was assigned to labels above, then labels should be used here and below.

@@ -787,22 +775,29 @@ def _addplot_columns(panid,panels,ydata,apdict,xdates,config):
mark = apdict['marker']
color = apdict['color']
alpha = apdict['alpha']
labels = apdict["labels"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use single quotes, apdict['labels'] instead of apdict["labels"], only for the sake of being consistent with existing/surrounding code style.

This is a good, general practice: Whenever modifying any existing code, keep to the style of the existing code (assuming that code has a consistent style to begin with). (If existing style is already inconsistent, then consider modifying the code to be consistent).

@DanielGoldfarb
Copy link
Collaborator

DanielGoldfarb commented Apr 13, 2022

Status update: I am presently reviewing all outstanding pull requests. did some experimenting with labels in general beyond just what is in this PR (see https://github.com/DanielGoldfarb/mplfinance/tree/ppseverin). When we finish this enhancement for labels I want to be able to support not just addplot, but also mav and hlines, vlines, alines, and tlines. That should not be difficult, but will require a bit more coding and a lot of testing (and adding some examples to the examples folder). There are a couple of other PRs that will be quicker and easier to merge, so I'm going to do those first and come back to this later.

@alexpvpmindustry
Copy link
Contributor

Status update: I am presently reviewing all outstanding pull requests. did some experimenting with labels in general beyond just what is in this PR (see https://github.com/DanielGoldfarb/mplfinance/tree/ppseverin). When we finish this enhancement for labels I want to be able to support not just addplot, but also mav and hlines, vlines, alines, and tlines. That should not be difficult, but will require a bit more coding and a lot of testing (and adding some examples to the examples folder). There are a couple of other PRs that will be quicker and easier to merge, so I'm going to do those first and come back to this later.

hello, thanks for all the work so far!
any progress on this labels PR? i am looking to contribute to get this PR completed.
let me know if there is anything that I can help with.

@DanielGoldfarb
Copy link
Collaborator

@alexpvpmindustry Thanks for your interesting in, and expression of gratitude for, mplfinance. Much appreciated!

Here's the status: I am solidly involved in another project at this time, and in preparing for JupyterCon (hope to see you there) so I will be giving minimal attention to mplfinance at least until towards the end of May.

That said, if you read through the conversion above, you can see where I have made several suggestions regarding the code. I've also pointed out where I think we should be going with labels, annotations, and legends, specifically with regard to for which aspects of mplfinance these things should be supported. (until now, there appears to be no movement on my suggestions).

If you would like to contribute, along the lines of the discussion and requests above, then I will be happy to review any contributions. (Keep in mind that it has been a while since this PR was first entered, and the trunk may have since migrated somewhat; so a fresh clone may be in order). Alternatively you can wait for me to make these changes, in which case it will most likely be the middle of June or later before it will be done. As mentioned above, a core part of this particular enhancement is complete testing to ensure no existing functionality has been broken.

@alexpvpmindustry
Copy link
Contributor

@DanielGoldfarb i see! sorry, i wont be available for the jupytercon, sounds exciting tho.
@ppseverin seems inactive for the past few months, so I think I'll clone his work and update it.
ill also include your suggestions, keeping in mind the new state of the repo.
if/when he/she comes back and if he chooses to, ill gladly let him continue.

@alexpvpmindustry
Copy link
Contributor

seems like @ppseverin has deleted his repo, ill make a new PR

@DanielGoldfarb
Copy link
Collaborator

This was implemented via #605

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.

3 participants