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
clone legend settings when regenerating legend in Qt figure #17794
Conversation
|
Thanks for working on this! Would it be possible to collect the public state we need and create a kwargs dictionary to pass to the legend call rather than updating after the fact? If it is possible we should try to avoid using private attributes (even internally). Something like kwargs = {k: getattr(old_legend, f'get_{k}')() for k in [...]}
ax.legend(**kwarg) |
|
@tacaswell Thanks for the review. The problem is not all the legend attributes have get function, so we may need to get the values from the attributes. Even then, we have some attributes which carry a lot of information (and are useful) like _legend_box (has text info and others), but this is not an argument to ax.legend(). So, I feel updating later, might be a better way than getting kwargs and calling ax.legend(*kwargs). Or the best way could be to have get_ functions for the rest (i.e., markerscale, scatterpoints, scatteryoffsets etc.) and modify _get_loc to get_loc(). Please let me know your thoughts. |
|
That is good point that we do not expose public accessors for everything so we need to reach in to the private attributes. I still think it is better to assemble a kwargs dictionary and pass it in to the lgeend call because some of the values (like |
|
@tacaswell I've made the changes. Please take a look. I have a query: What is the expected behavior when there is no legend initially, and then we tick re-generate legend option? Do we draw the legend? |
|
The current behavior is to generate a legend using the default kwargs which I think makes sense. |
|
This is looking on the right path! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks correct and I interactively tested the original issue.
|
Ideally we would want some sort of automated test on this, but we don't currently have any coverage of this part of the code and it would be unfair to ask @dsandeep0138 to get that going in order to get this change in. That said, if you want to take on how to test this @dsandeep0138 (either here or in a follow on PR) that would be great :) |
I'm figuring out how to write a test for this! More clearly, I'm trying to figure out how to tick the checkbox (to re-generate legend) from the test module, but I'm stuck and not really sure of how to do this :) I will try to figure it out as part of another PR. Thank you! |
|
If you can get a hold of the Qt objects there should be a You may have better luck fabricating the input to this function and then directly calling it. |
|
@anntzer and @tacaswell, I have included the set_draggable changes. Can you please review and approve? Thank you. |
| kwargs['mode'] = old_legend._mode | ||
| kwargs['title'] = old_legend.get_title().get_text() | ||
| kwargs['frameon'] = old_legend.get_frame_on() | ||
| kwargs['bbox_to_anchor'] = old_legend._bbox |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this work without bbox_transform?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @QuLogic, bbox_transform was used and then loc/bbox_to_anchor was updated. Since we directly update 'loc' and 'bbox_to_anchor' from the old legend, we don't need to do bbox_transform again. Please let me know if you have any questions, or some suggestions from your end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bbox_to_anchor and bbox_transform are combined to produce Legend._bbox_to_anchor though, yet you've only saved bbox_to_anchor in Legend._bbox. What does that have to do with loc?
|
Hi @dsandeep0138 I know this languished for a while, but you need to ping for PRs to get reviewed. This is also waiting on an answer to @QuLogic comment above... |
|
Closing as orphaned. Sorry this didn't get in! |


Fixes #17775