Skip to content

Secondary_axis combined with interpolation functions generates overlapped axis labels #19205

@dihm

Description

@dihm

Bug report

Bug summary

When using the new Axes.axes.secondary_xaxis features in combination with interpolated forward/inverse mapping functions, extra axis labels are produced at either end of the axis.

Code for reproduction

While this example would be trivial to put into proper mapping functions, my ultimate need is to map between empirically derived data (ie I have and x dataset and a second, derived x dataset that is not trivially related).

fig, ax = plt.subplots(1)

x1 = np.linspace(1,1000,10)
x2 = x1/30
y = x1**(-2)

ax.plot(x1,y,'k-')

def forward(x):
    return np.interp(x,x1,x2)

def inverse(x):
    return np.interp(x,x2,x1)

secax = ax.secondary_xaxis('top',functions=(forward,inverse))
secax.set_xlabel('x/30')

ax.set_xlabel('x')
ax.set_ylabel('x^-2')
plt.show()

Actual outcome

It appears that tick labels that are not in the shown range are all being stacked at the axis limits for the secondary axis.

image

Expected outcome

In this trivial example, using the direction transformation functions (x/30 and x*30) does not produce the stacked tick labels.

image

Matplotlib version

  • Operating system: Windows 10
  • Matplotlib version: 3.3.2
  • Matplotlib backend (print(matplotlib.get_backend())): ipykernel.pylab.backend_inline
  • Python version: 3.8.5
  • Jupyter version (if applicable): (client) 6.1.7
  • Other libraries:
  • Installation: conda, default channel

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions