8000 Possible issue in hexbin using weights · Issue #20877 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Possible issue in hexbin using weights #20877
Closed
@Enzoupi

Description

@Enzoupi

I am facing a problem in matplotlib, using hexbin with weights (argument C=).

When I am filling the C argument, not only the ouput color changes but also the shape. Here is a very simple code snippet reproducing the behavior:

  npts = int(2e5)
  
  # Create a random distribution and another one as it perturbation
  x1 = np.random.randint(0,3000,npts)
  x2 = x1 + np.random.normal(loc=0,scale=75,size=npts)
  
  # Same for the second axis variable
  y1 = np.random.randint(280,310,npts)
  y2 = y1 + np.random.normal(loc=0,scale=2,size=npts)
  
  # Plot
  fig, axes = plt.subplots(2,1)
  ax = axes[0]
  ax.hexbin(y2-y1,x1,mincnt=1,extent=[-8,8,0,3000], gridsize=150) 
  #
  ax = axes[1]
  res = ax.hexbin(y2-y1,x1,C=x1,mincnt=1,extent=[-8,8,0,3000], gridsize=150)
  
  fig.savefig(f"hexbin_weights.png")
  plt.show()

And the corresponding output:
Snippet output

To my understanding, as the x and y coordinates of the points are identical, only the color on the two plots should change. However, it is clearly not the case. Is it another parameter that is changing without me being aware of ? Is C not doing what I expect it to do ?

Thanks in advance for any help !

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0