FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[Bug]: Hexbin gridsize interpreted differently for x and y · Issue #21349 · matplotlib/matplotlib · GitHub

Repository navigation

[Bug]: Hexbin gridsize interpreted differently for x and y #21349

Closed

Description

Bug summary

gridsize results in 2x the expected number of elements in y-direction

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

np.random.seed(19680801)
n = 100000
x = np.random.standard_normal(n)
y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n)

fig, ax = plt.subplots(figsize=(6, 6))
h = ax.hexbin(x, y, gridsize=(10, 10), marginals=True, reduce_C_function=np.sum)

Actual outcome

Expected outcome

This image was taken with gridsize=(10, 5) but should be the result of gridsize=(10, 10).

Activity

  1. added this to the v3.5.1 milestone on Oct 13, 2021
  2. dstansby commented on Oct 14, 2021

    Member

    Does anyone have opinions on deprecating and remove support for marginals altogether? I'd say it's an oddity within Matplotlib (we don't support it for pcolormesh, imshow etc.), and is high enough level to be out of scope (but probably the remit of say, seaborn)

  3. jklymak commented on Oct 14, 2021

    Member

    @dstansby, I think the marginals are an orthogonal issue. The point is that the hexes are asymmetric. I think its easier to see if we set the aspect ratio of the data and plot to 1:

    import matplotlib.pyplot as plt
    import numpy as np
    
    np.random.seed(19680801)
    n = 100000
    x = np.random.standard_normal(n)
    y = np.random.standard_normal(n)
    
    fig, ax = plt.subplots(figsize=(6, 6))
    h = ax.hexbin(x, y, gridsize=(10, 10), marginals=True, reduce_C_function=np.sum)
    ax.set_aspect(1)
    plt.show()

  4. anntzer commented on Oct 14, 2021

    Contributor

    (I agree with @dstansby re: deprecating marginals, although it should be possible to write an example showcasing how to do them -- not only for hexbin, but also for other 2D maps.)

  5. dstansby commented on Oct 14, 2021

    Member

    Sorry for the off topic comment - I'll open a new issue for that.

  6. modified the milestones: v3.5.1, v3.5.2 on Dec 10, 2021
  7. modified the milestones: v3.5.2, v3.5.3 on Apr 30, 2022
  8. tacaswell commented on Jun 16, 2022

    Member

    We talked about this on the call this week https://hackmd.io/49a-u44CTja02xQRaG88JA?view#hexbin

    The consensus action is :

    • update the docstring to be clear about what it is doing
    • possibly add a second mutually-exclusive keyword to go with gridsize that has the meaning expected

    The docstring currently says:

           Alternatively, if a tuple (*nx*, *ny*), the number of hexagons
           in the *x*-direction and the *y*-direction.
    

    Which is at best ambigious as if in these examples you count between hexs that are vertically aligned you (rather than zig-zag) you do get the expected number. To be clear, the stacking is ABAB, if you count the number of A you get the expected number.

    We also need to inspect the code and make sure that this is not doing something about counting along the 60-degree diagonal and then filling in how many y rows we need. This would be consistent with what is done in the case of only passing 1 number (where the number of y-bins is xbin / sqrt(3) )

  9. timhoffm commented on Jun 18, 2022

    MemberAuthor

    I think clear documentation is sufficient. The common use case of regular hexagons is handled by the single-integer parameter. Asymmetric relations are less common and can be achieved using an appropriate scaling factor. We don't need additional mutually exclusive parameters for that.

  10. modified the milestones: v3.5.3, v3.5.4 on Jul 21, 2022
  11. modified the milestones: v3.5.4, v3.6.1 on Sep 25, 2022
  12. modified the milestones: v3.6.1, v3.6.2 on Oct 6, 2022
  13. added a commit that references this issue on Oct 16, 2022
    91dd808
  14. added a commit that references this issue on Oct 18, 2022
    36a4261
  15. added a commit that references this issue on Dec 19, 2022
    bf32e7c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL