Skip to content

Fix errorbar autoscaling inconsistency on log axes (fixes #31462)#31478

Open
Vikash-Kumar-23 wants to merge 1 commit intomatplotlib:mainfrom
Vikash-Kumar-23:fix/errorbar-log-autoscale-31462
Open

Fix errorbar autoscaling inconsistency on log axes (fixes #31462)#31478
Vikash-Kumar-23 wants to merge 1 commit intomatplotlib:mainfrom
Vikash-Kumar-23:fix/errorbar-log-autoscale-31462

Conversation

@Vikash-Kumar-23
Copy link
Copy Markdown
Contributor

PR summary

closes #31462

This PR fixes an autoscaling inconsistency for errorbar on log-scaled axes.

Why this change is necessary

When log scale is set before calling errorbar, autoscaling can produce incorrect lower limits (often collapsing near 1).
If errorbar is called first and log scale is applied afterward, the limits are correct.

This order-dependent behavior is unexpected and inconsistent.


What this PR changes

  • Applies a minimal, localized fix in the autoscale path used by errorbar
  • Adds a regression test to ensure both call orders now produce consistent limits

Before fix (incorrect behavior)

Screenshot 2026-04-08 201640
  • Lower limits collapse near ~1 when using scale → errorbar

After fix (correct behavior)

image
  • Both orders now produce consistent and reasonable limits

Minimum self-contained example

import numpy as np
import matplotlib.pyplot as plt

x = 10 ** np.array([18, 18.1, 18.2, 18.3])
y = np.array([100, 80, 60, 30])
yerr = np.ones_like(y) * 10

# Order 1: scale -> errorbar
fig1, ax1 = plt.subplots()
ax1.set_xscale("log")
ax1.set_yscale("log")
ax1.errorbar(x, y, yerr=yerr)

# Order 2: errorbar -> scale
fig2, ax2 = plt.subplots()
ax2.errorbar(x, y, yerr=yerr)
ax2.set_xscale("log")
ax2.set_yscale("log")

print(ax1.get_xlim(), ax1.get_ylim())
print(ax2.get_xlim(), ax2.get_ylim())

Expected after this PR

  • Both orders produce consistent, reasonable limits

AI Disclosure

AI tools were used to assist in drafting text and suggesting validation scenarios.
All code changes, final implementation decisions, and verification were done manually.


PR checklist

minx = np.nanmin(datalim.xmin)
maxx = np.nanmax(datalim.xmax)
miny = np.nanmin(datalim.ymin)
maxy = np.nanmax(datalim.ymax)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why this worked fine for the linear scale but not for the log scale?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Errorbar plot on log-scaled Axes sets incorrect automatic lower limits

3 participants