proplot-dev / proplot

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

bug: wrong xticklabels with log scale dualx #460

Open kinyatoride opened 1 month ago

kinyatoride commented 1 month 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 1 month 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 1 month ago

Which produces image