Skip to content

Artefacts in hist2d and hexbin output #343

@Jhsmit

Description

@Jhsmit

When I'm making hist2d or hexbin plots in proplot, I have an issue where in the hist2d the rectangles arent correctly shaped, specifically it seems the lowest pixel row, and when I use hexbin, some of the hexes appear to be smaller or below other hexes.

Proplot code:

import proplot as pplt
import numpy as np
import matplotlib.pyplot as plt

# Sample data
N = 500
state = np.random.RandomState(51423)
x = state.normal(size=(N,))
y = state.normal(size=(N,))
bins = pplt.arange(-3, 3, 0.25)

fig, axs = pplt.subplots(refaspect=1, width='50mm')

axs[0].hist2d(
    x, y, bins, vmin=0, vmax=10,
    cmap='Blues',
)

Proplot result:

proplot_example_hist2d

Zoom of the rectangles:

image

Matplotlib code:

import numpy as np
import matplotlib.pyplot as plt

# Sample data
N = 500
state = np.random.RandomState(51423)
x = state.normal(size=(N,))
y = state.normal(size=(N,))
bins = np.arange(-3, 3.2, 0.25)

fig, ax = plt.subplots()
ax.set_aspect(1)

ax.hist2d(x, y, bins, cmap='Blues', vmin=0, vmax=10)

Matplotlib result

matplotlib_hist2d

For the hist2d it isnt too bad, especially with high resolutions (since its appears only to be the lowest pixel line). pdf output has the same effect.

The hexbin looks like this:

Proplot:

...
axs[0].hexbin(
    x, y, gridsize=20, vmin=0, vmax=10,
    cmap='Blues',
)

proplot_example_hexbin

Matplotlib:

ax.hexbin(x, y, cmap='Blues', gridsize=20, vmin=0, vmax=10)

matplotlib_hexbin

Version info:
proplot==0.9.5
matplotlib==3.4.3

Using py39 on windows 11

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions