proplot-dev / proplot

🎨 A succinct matplotlib wrapper for making beautiful, publication-quality graphics
https://proplot.readthedocs.io
MIT License
1.12k stars 102 forks source link

bug: wrong xticklabels with log scale dualx #460

Open kinyatoride opened 3 months ago

kinyatoride commented 3 months ago

Description

dualx seems to have an issue handling log scale axis.

Steps to reproduce

import numpy as np
import proplot as pplt

x = np.logspace(-1, 1, 100)

fig, ax = pplt.subplots()
ax.semilogx(x, np.sin(x))
ax.dualx(lambda x: 1/x)

The top tick labels are a mess. output

Equivalent steps in matplotlib

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0.1, 10, 1000)
fig, ax = plt.subplots()
ax.semilogx(x, np.sin(x))
ax.grid()
ax.secondary_xaxis('top', functions=(lambda x: 1/x, lambda x: 1/x))

output1

Proplot version

3.4.3 0.9.7

cvanelteren commented 3 months ago

Not a real solution but for now you could do:

import numpy as np
import proplot as plt

x = np.logspace(-1, 1, 100)
fig, ax = plt.subplots()
ax.semilogx(x, np.sin(x))
tax = ax.dualx(lambda x: x)
tax.invert_xaxis()
plt.show(block=1)
cvanelteren commented 3 months ago

Which produces image