Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow linear scaling for marker sizes in scatter #25259

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

chahak13
Copy link
Contributor

@chahak13 chahak13 commented Feb 19, 2023

PR Summary

Issue #1101 talks about having a kwarg called markersize for the scatter function that can take sizes on a linear scale since it is currently on a quadratic scale with the kwarg s. This PR adds a new kwarg to scatter called markersize and adds the _markerscale attribute to _CollectionWithSizes. Using these, the size of the markers can be set with a linear scale. The default is still to use the s parameter if nothing is given and markersizes are used only if specifically provided instead of s.

After discussion, the scope was changed to adding markersize as an alias to s in scatter and add a variable markerscale that will allow the linear/quadratic scaling for the size values.

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (and pytest passes)
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

@chahak13 chahak13 marked this pull request as ready for review February 26, 2023 03:10
@jklymak
Copy link
Member

jklymak commented Feb 26, 2023

I think this misses the semantic difference between s in scatter and markersize in plot. In scatter, s is meant to be an array in scatter, whereas markersize cannot be an array in plot. I think the changes proposed here make the difference even more confusing, and we should be very deliberate about what we do here.

First, I don't think you should snake the scaling through to the low-level object. get_sizes should just return what it's always returned, with an explanation in the docs.

Second, I think you should consider that s=array is how to specify arrays for the markersizes, and markersize=float is a shortcut for plot-like scaling if s is not provided. eg, markersize should not accept an array. If s and markersize are both specified, it should probably error out.

@chahak13
Copy link
Contributor Author

I don't think you should snake the scaling through to the low-level object. get_sizes should just return what it's always returned, with an explanation in the docs.

My only concern with this is if the user has provided the sizes in the linear scale, then it makes sense to return the sizes that were "set" instead of the modified ones. But this goes hand in hand with the discussion of what we want markersize to be doing.

There are two things that the original issue/discussion covered: 1. Having markersize (or better) as a more user-friendly kwarg and 2. To provide a way to have linearly scaling sizes. For 2, it makes more sense to me to be able to add an array for markersize than to not because that is taking away functionality that can be provided without much effort. If the consensus is to not allow arrays, then that should not be difficult.

I agree with not allowing both s and markersize at the same time. It does that already, that's the first check.

@jklymak
Copy link
Member

jklymak commented Feb 27, 2023

My tendency is to be pretty conservative when it comes to multiple ways to do the same thing. I'd be very concerned about the Container returning different values for size based on how the axes helper created it. Yes, you have a new flag on the Container, but downstream libraries don't know that, so if anyone is depending on the markersize being in one units or another, they are not going to know to check the markerscale.

@chahak13
Copy link
Contributor Author

I understand that, but wouldn't having the default behaviour such that it doesn't change anything that already exists resolve that issue? And if they are instead using markersize then they would know already what will be returned based on the docs?

@chahak13
Copy link
Contributor Author

chahak13 commented Mar 9, 2023

Meeting 9/3: Think instead about making markersize an alias for s and have a scaling factor as the kwarg to control all this. Also look into how to make this scaling factor consistent with all the getter/setters.

@jklymak
Copy link
Member

jklymak commented Apr 6, 2023

@chahak13 does this still need discussion or do you have enough guidance?

@chahak13
Copy link
Contributor Author

chahak13 commented Apr 6, 2023

@jklymak sorry, I should've put a comment in earlier but I've changed markersize to be an alias for s and added a markerscale variable as we discussed last time in the meeting.

@chahak13
Copy link
Contributor Author

chahak13 commented Apr 6, 2023

Sorry for the label, was looking for something else!

@chahak13 chahak13 changed the title Implement a markersize kwarg for scatter Allow linear scaling for marker sizes in scatter Apr 27, 2023
@chahak13 chahak13 force-pushed the scatter_markersize branch from 52e4073 to 0abd1b7 Compare April 27, 2023 03:05
@chahak13 chahak13 marked this pull request as draft April 27, 2023 03:48
@chahak13 chahak13 force-pushed the scatter_markersize branch from 472aef6 to 34c0620 Compare May 8, 2023 22:28
@chahak13 chahak13 force-pushed the scatter_markersize branch from 34c0620 to 75c0084 Compare May 9, 2023 23:26
@ksunden
Copy link
Member

ksunden commented May 11, 2023

Needs the aliases added to the mypy-stubtest-allowlist.txt file:

# Aliases (dynamically generated, not type hinted)

Since aliases are dynamically generated, they are not type hinted. Users wanting to use static type checking should use the canonical name (which is a pretty fair tradeoff, and usually results in more readable code, aliases are more helpful for interactive work where using short names or not needing to remember "is there an s on this function?" is more useful)

Adding to the list is just how we silence stubtest, which looks at what is included at runtime.

@chahak13 chahak13 marked this pull request as ready for review May 11, 2023 22:23
@ksunden
Copy link
Member

ksunden commented Feb 1, 2024

Ah, the conflict is because since this was opened I actually started dynamically finding aliases so they don't need to be in the mypy-stubtest-allowlist.txt file any more

@@ -4568,6 +4568,12 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
or ``nan``). If ``True`` the points are drawn with the *bad*
colormap color (see `.Colormap.set_bad`).

Copy link
Member

@timhoffm timhoffm Feb 22, 2024

Choose a reason for hiding this comment

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

I would not call this *scale, because it could be interpreted as "linear scaling factor" - and we do this e.g. at mutation_scale in https://matplotlib.org/devdocs/api/_as_gen/matplotlib.patches.FancyArrowPatch.html#matplotlib.patches.FancyArrowPatch. Suggestion: markerscaling or maybe just scaling - I have some sympathy to push this down to collectionWithSizes later. A scaling parameter would be meaningful there so that we have consistent naming and don't need to translate the markerscaling kwarg. Also, I believe scatter(..., scaling=...) is clear enough.

Also, 1 and 2 are not very telling as values. How about "linear"/"quadratic" or "linear"/"square" or "length"/"area"?

Edit: There seems to be a mismatch between the discussion and code whether to push the scaling down to CollectionWithSizes. I've written the above under the impression that pushing down should not (yet?) be done in this PR. - Rethinking, I claim that pushing down is very much to be preferred - not being able to reflect the high-level scaling concept in the underlying artists would be a major shortcoming. I'm +1 on implementing this immediately in CollectionWithSizes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants