Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: xlim not calculated correctly for inverted log plot #32336

Description

@kalen-sj

Bug summary

Previous behavior (3.2.2) of making a certain plot (inverted axis, log, w/shared axis) showed data appropriately distributed across the plot. New behavior (3.10.9) shows data bunched up to one side. Code to reproduce is below.

Code for reproduction

# Demonstrates problem with xlim in recent (3.10.9) version
# of matplotlib. In 3.10.9, all of the data are pushed off 
# to one side of the figure. 

# In matplotlib 3.2.2, the data are appropriately distributed 
# across the plot.

import numpy as np
import matplotlib.pyplot as plt

# Some data to plot.
res = np.array([2.82481734, 2.60724989, 2.03974669, 1.4043936 ])
res_err = np.array([0.1, 0.1, 0.1 , 0.1])

ph = np.array([-3.09230529,  2.65380027,  1.50135906,  2.74889725])
ph_err = np.array([0.1, 0.1, 0.1 , 0.1])

freqs = np.array([ 687.5  ,  875.   , 1328.125, 6281.25 ])

# Figure setup.
gs_top = plt.GridSpec(3, 1, hspace=0)
gs_base = plt.GridSpec(3, 1)
fig = plt.figure()

ax_res = fig.add_subplot(gs_top[0, :])
ax_res.invert_xaxis()
ax_res.set_xscale('log')

ax_ph = fig.add_subplot(gs_top[1, :], sharex=ax_res)
ax_ph.set_xscale('log')

ax_pseudo = fig.add_subplot(gs_base[2, :])

# Shows the problem better with grids on.
ax_res.grid(axis='both', which='both')
ax_ph.grid(axis='both', which='both')
ax_pseudo.grid(axis='both', which='both')

# Plot the data.
ax_res.errorbar(freqs, res, yerr=res_err, fmt='o')

ax_ph.errorbar(freqs, ph*180/np.pi, yerr=ph_err*180/np.pi, fmt='o')

skins = np.array([100, 200, 400, 800])
ax_pseudo.plot(skins, res, 'o')

fig.show()

Actual outcome

Data is bunched up on one side of plot.

Expected outcome

Data appropriately distributed across the plot.

Additional information

Incorrect calculation of xlim is suspected.

Worked before with (at least):
matplotlib 3.2.2 (numpy 1.21.6)

Incorrect behavior with:
matplotlib 3.10.9 (numpy 1.26.4)

Operating system

Ubuntu 26.04.1 LTS

Matplotlib Version

3.10.9

Matplotlib Backend

qtagg

Python version

Python 3.12.12

Jupyter version

N/A

Installation

conda

Activity

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions