Skip to content

Why is smart_bounds() being deprecated? #15417

Closed

Description

@cristobaltapia

I am getting the following warning when running my code that uses smart_bounds:

The set_smart_bounds function was deprecated in Matplotlib 3.2 and will be removed 
two minor releases later.

What should we use to get the same effect in the future then?

Activity

  1. jklymak commented on Oct 14, 2019

    @jklymak
    Member

    What effect are you trying to achieve. This was relatively robustly discussed in the PR. You can look up the issue using the search function

  2. cristobaltapia commented on Oct 14, 2019

    @cristobaltapia
    Author

    I read the PR, but was not clear to me why the functionality was not deemed important. What I want is for the axis to span only the region where the datapoints are.

  3. jklymak commented on Oct 14, 2019

    @jklymak
    Member

    ax.margins(0) does that, I think?

  4. cristobaltapia commented on Oct 14, 2019

    @cristobaltapia
    Author

    No, that is not what I meant. What I mean is e.g. if I set the limits of the y-axis to span [0-100] but my data spans [20-100], then the left spine would by drawn starting from 20 up to 100. But there will be an empty space from 0 to 20 (no line would be drawn).

  5. jklymak commented on Oct 14, 2019

    @jklymak
    Member

    spine.set_bounds(x.min(), x.max())? https://matplotlib.org/3.1.1/api/spines_api.html#matplotlib.spines.Spine.set_bounds

    I think the feature was deemed a bit strange to merit the amount of code and maintenance involved. But if you can make a strong case for it being useful folks may change their minds. (ping @efiring)

  6. tacaswell commented on Oct 14, 2019

    @tacaswell
    Member

    xref #11004

  7. cristobaltapia commented on Oct 14, 2019

    @cristobaltapia
    Author

    Well, I don't have strong sentiments attached to the function (although I have used it a lot in the past couple of years), but I think the functionality is nice. I read in Tufte's book [1] about the concept of "double-functioning labels", where the idea is to mark the range of your data with the spine. In the details it is not exactly as what set_smart_bounds() does, but quite similar. However, I guess that using spine.set_bounds(x.min(), x.max()) is also a viable solution.

    [1] Tufte, Edward R. (1986). "The Visual Display of Quantitative Information", Graphics Press, Cheshire, CT, USA

  8. jklymak commented on Oct 14, 2019

    @jklymak
    Member

    Sure, but why wouldn't you just set the xlim to [20, 100] and not have the blank space?

  9. cristobaltapia commented on Oct 14, 2019

    @cristobaltapia
    Author

    In the case where it is relevant to have the zero as well. If I am showing some ratios it helps to have the full range from zero, so that the magnitude is correctly interpreted.

  10. jklymak commented on Oct 14, 2019

    @jklymak
    Member

    How does the viewer know zero is there somewhere? Maybe you could show an example?

  11. tacaswell commented on Oct 14, 2019

    @tacaswell
    Member

    One of the hardest things for us to know is what parts of the library are actually used. It is good to know this feature actually has users :)

    I think the question is how are you using it and how onerous the alternatives are?

  12. added this to the v3.2.0 milestone on Oct 14, 2019
  13. cristobaltapia commented on Oct 15, 2019

    @cristobaltapia
    Author

    Here are some examples:

    The first one is what I described above, where I have some ratios and it is important to know where zero is (so that large variations actually mean large variations and not just that we are in a different scale). I think is nice sometimes to just mark the range this way.

    figure_1

    The other way I use it is in normal plots, where I just like the effect of the spines to be separated, like this:

    figure_2

    Maybe in the first example (as pointed out by @jklymak) it would be better to also mark the zero in the y-axis. But those are my main uses for the function.

  14. jklymak commented on Oct 15, 2019

    @jklymak
    Member

    Seems those would both work w/ set_bounds?

  15. cristobaltapia commented on Oct 21, 2019

    @cristobaltapia
    Author

    Yes, it would. The set_smart_bounds() is (as I see it) only a shortcut, especially useful when more than one data set is plotted (then the maximum and minimum of all the plotted data has to be considered).

  16. efiring commented on Oct 22, 2019

    @efiring
    Member

    Given that set_bounds seems adequate for the use cases, and has the advantage of being clear and explicit, I think this can be closed.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions