Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Bug]: Wrong scaling of NonUniformImage with logarithmic axes #29368

Copy link
Copy link
Closed
@david-zwicker

Description

@david-zwicker
Issue body actions

Bug summary

I'm trying to produce a density plot of logarithmically spaced data. Using NonUniformImage used to work before matplotlib version 3.10, where I know exhibit a weirdly scaled axis.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.image import NonUniformImage

x = np.linspace(0, 1, 2)
y = np.geomspace(1e1, 1e5, 3)
z = np.random.uniform(size=(len(x), len(y)))

_, (ax1, ax2) = plt.subplots(ncols=2)

# create the non-uniform image
im = NonUniformImage(ax1, extent=[0, 1, 1e0, 1e6], origin="lower")
im.set_data(x, y, z.T)
ax1.add_image(im)
ax1.set_yscale("log")
ax1.set_ylim(1e0, 1e6)  # omitting this leads to very weird behavior
ax1.set_title("NonUniformImage")

# use pcolormesh to get reference image
ax2.pcolormesh([0, 0.5, 1], [1e0, 1e2, 1e4, 1e6], z.T)
ax2.set_yscale("log")
ax2.set_title("pcolormesh")

Actual outcome

The code above produces the following image

b32e9b79-dd12-44f9-b472-6ef09f886ac3

Expected outcome

I expect the left panel to look like the right panel, which was produced using pcolormesh. The reason I don't want to use pcolormesh for these plots is that the quality in PDFs is often much worse (with lines showing up between patches) and the file size can easily be 10 times larger.

Additional information

I recently asked a related question on Stackoverflow, which has some additional details.

Operating system

OS/X

Matplotlib Version

3.10.0

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

3.12.8

Jupyter version

7.3.1

Installation

conda

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.