Skip to content

dualx not correctly shown #441

@miniufo

Description

@miniufo

There is a dualx funcitonality that could be very useful in labelling the wavelength and wavenumber simultaneously. Here is an example from a paper:

Image

The x-axis at the bottom shows the wavenumber (cycle per km) while the one at the top shows the wavelength (km), as wavenumber = 1 / wavelength.

I tried this with the following simple codes:

import ultraplot as uplt
import numpy as np
import xarray as xr

data = xr.DataArray(np.random.randn(100)+2, dims=['wn'], coords={'wn':np.logspace(-2, 2, 100)})

fig, axes = uplt.subplots(figsize=(5,4))

ax = axes[0]
ax.plot(data)
ax.set_xscale('log')
ax.set_yscale('log')
ax.format(xformatter='log')
ax.set_xlabel('wavenumber (cycle per km)')
ax.dualx(
    lambda x: 1 / x,
    label="length scale (km)",
    formatter="log",
    grid=True,
    color='k',
    gridcolor='k',
)

which shows

Image

It is a bit strange to me that the two x-axes do not align exactly. Just want to know how to do this correctly. Thanks very much.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions