Skip to content

[Bug]: sticky edge related changes for datetime plots #28567

Closed

Description

@rcomer

Bug summary

Having just picked up v3.9.1, we are seeing downstream image test failures due to additional whitespace in contourf and pcolor plots that use datetimes. The change bisects to #28393.

Code for reproduction

import datetime

import numpy as np
import matplotlib.pyplot as plt

dts = [datetime.datetime(2009, 9, 9, 17, 0) + datetime.timedelta(minutes=n) for n in range(10, 61, 10)]
foo = range(5)
data = np.arange(30).reshape(6, 5)

plt.contourf(foo, dts, data)
plt.show()

Actual outcome

image

Expected outcome

Before #28393 I get
image

Additional information

No response

Operating system

Ubuntu

Matplotlib Version

v3.9.1 and main

Matplotlib Backend

No response

Python version

3.12

Jupyter version

No response

Installation

conda

Activity

  1. changed the title [-][Bug]: sticky-related changes for datetime plots[/-] [+][Bug]: sticky edge related changes for datetime plots[/+] on Jul 13, 2024
  2. rcomer commented on Jul 14, 2024

    @rcomer
    MemberAuthor

    If I get hold of the contourset and the axes here, I have

    In [4]: cs.sticky_edges.y[0] == ax.dataLim.ymin
    Out[4]: np.True_
    
    In [5]: cs.sticky_edges.y[1] == ax.dataLim.ymax
    Out[5]: np.True_
    
    In [6]: cs.sticky_edges.x[0] == ax.dataLim.xmin
    Out[6]: np.True_
    
    In [7]: cs.sticky_edges.x[1] == ax.dataLim.xmax
    Out[7]: np.True_

    😕

  3. rcomer commented on Jul 14, 2024

    @rcomer
    MemberAuthor

    It seems like, by the time we get the the relevant comparison, somehow the sticky limits got flipped:

    diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py
    index 4606e5c01a..9d5274d9e6 100644
    --- a/lib/matplotlib/axes/_base.py
    +++ b/lib/matplotlib/axes/_base.py
    @@ -2969,12 +2969,14 @@ class _AxesBase(martist.Artist):
                 # Index of largest element < x0 + tol, if any.
                 i0 = stickies.searchsorted(x0 + tol) - 1
                 x0bound = stickies[i0] if i0 != -1 else None
    +            print(f'{x0bound=}, {x0=}')
                 # Ensure the boundary acts only if the sticky is the extreme value
                 if x0bound is not None and x0bound > x0:
                     x0bound = None
                 # Index of smallest element > x1 - tol, if any.
                 i1 = stickies.searchsorted(x1 - tol)
                 x1bound = stickies[i1] if i1 != len(stickies) else None
    +            print(f'{x1bound=}, {x1=}')
                 # Ensure the boundary acts only if the sticky is the extreme value
                 if x1bound is not None and x1bound < x1:
                     x1bound = None
    x0bound=np.float64(14496.75), x0=np.float64(14496.715277777777)
    x1bound=np.float64(14496.715277777777), x1=np.float64(14496.75)
    
  4. rcomer commented on Jul 14, 2024

    @rcomer
    MemberAuthor

    So I guess the problem is basically the same as #28223 in that the data range is less than the tolerance. If I make the tolerance only a function of the range

    tol = 1e-5 * abs(x1 - x0)

    as suggested at #28393 (comment), this is fixed and no existing tests break.

  5. ksunden commented on Jul 14, 2024

    @ksunden
    Member

    Yeah, I came to the same conclusion... I think that works, and makes more sense to me... I can't think of a case where the absolute magnitude is preferred to the range of the data for this computation.

  6. added this to the v3.9.2 milestone on Jul 17, 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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions