Skip to content

matplotlib.pyplot.scatter should accept "markersize" for consistency #1101

Open

Description

@adrn

I find it confusing that scatter() accepts the keyword argument "s" instead of markersize / ms like plot(). Was this a design choice? If so, why is "size" an invalid option? "s" is simply too ambiguous when other functions such as text() accept an "s" keyword which means string.

Activity

  1. efiring commented on Aug 17, 2012

    @efiring
    Member

    I don't see the conflict with "s" as "string" as too bad; the real problem here in my mind is again the unfortunate legacy from Matlab's scatter function in which all Collection "size" scaling is based on the square root of the "size" parameter instead of the parameter itself. In other words, this early bad design choice is deeply embedded.

    Your suggestion of allowing a "markersize" (presumably with alias, "ms") kwarg may provide a good route out of this Matlab trap, although it is not the greatest name for the scale parameter for Collections in general. Certainly it makes good sense for scatter, though.

  2. akhmerov commented on Aug 18, 2012

    @akhmerov
    Contributor

    Within matplotlib itself, it's relatively easy to rewrite the size to be a linear scale. Would it be acceptable given the backwards compatibility concerns? If I understand correctly, pyplot is designed to provide as close of a copy of Matlab interface. If so, the best solution, I guess, would be to have Collections sizes argument a linear scale, Axes.scatter sizes also linear, and pyplot.scatter s being area. It would be preferential, however to also provide a pure OO GUI interface as well (right now it's very hard without pyplot).

  3. dmcdougall commented on Aug 21, 2012

    @dmcdougall
    Member

    Schematically, is the following a good idea?

    Inside the Axes.scatter method:

    # ...
    # Stuff
    # ...
    
    kwargs.pop('markersize', None)
    if c is not None and markersize is not None:
        raise Error
    elif c is None and markersize is not None:
        c = np.square(markersize)
    elif c is None and markersize is None:
       raise AnotherError
    # else continue with old code
    # ...

    The idea is that if the user specifies markersize, the size of the points will be as for a Line2D object. Otherwise, the old area scale code is used.

  4. added this to the milestone on Aug 18, 2014
  5. story645 commented on May 31, 2016

    @story645
    Member

    does dealing with this simultaneously deal with #1099? (they're sort of addressing the same issue from two different sides)

  6. efiring commented on May 31, 2016

    @efiring
    Member

    Yes, any action dealing with either should address both of them.

  7. story645 commented on May 31, 2016

    @story645
    Member

    so at that point are they dupes?

  8. efiring commented on May 31, 2016

    @efiring
    Member

    Not exactly. I think the thing to do is leave them both open. Your comment links them, so that anyone wanting to work on one will see the discussion on the other.

  9. modified the milestones: , on Sep 24, 2017
  10. chahak13 commented on Feb 10, 2023

    @chahak13
    Contributor

    On the call today we discussed this and reached a consensus that this should be worked on. An idea discussed to start out with was to add a kwarg that would set the marker sizes in linear scale instead of the quadratic being done right now and if both s and markersize (or whatever we decide to call it) are provided then we error out as quickly with a detailed error message about it. The current state of action will be to first check the feasibility of implementing this. If this starts becoming unnecessarily complicated, we will rethink this.

    cc: @tacaswell @efiring @jklymak @ksunden @melissawm @timhoffm @rcomer (Tim, tagging you since this would entail an API change probably)

  11. chahak13 commented on Feb 19, 2023

    @chahak13
    Contributor

    I think we need to decide on if we want to make this just a thing for scatter or an inherent property of _CollectionWithSizes. If we want to do it just for scatter then we can work around by handling the kwarg in the scatter function and "setting" the sizes as the squared value of the kwarg but this will create an inconsistency between what was set and what would be returned/used get_sizes/set_sizes.

    On the other hand, we can create a new scaling (placeholder name) attribute for _CollectionWithSizes that determines if the size was set with a linear scale or a quadratic scale and then sets the sizes with/without the np.sqrt(self._sizes) call. This way it gets handled by _CollectionWithSizes and can be extended to all the derived classes. I have a toy implementation for this if it sounds like something we want to do. It requires changes in _axes.py, collections.py, and mplot3d/art3d.py to handle 3D scatter.

  12. github-actions commented on Feb 21, 2024

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  13. added
    status: inactive
    on Feb 21, 2024
  14. added
    keep
    and removed
    status: inactive
    on Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    API: changesAPI: consistencyNew featurekeep

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions