corner.py icon indicating copy to clipboard operation
corner.py copied to clipboard

axes_scale argument does not work?

Open anderss3 opened this issue 2 years ago • 3 comments

Hello,

I am using a corner plot with 5 parameters. I would like the third parameter to be plotted using a log scale. I passed in this parameter but it does not seem to make any difference.

axes_scale=['linear', 'linear', 'log', 'linear', 'linear']

Am I specifying it correctly or is this a bug?

Thanks.

anderss3 avatar Mar 18 '23 08:03 anderss3

Please put together a minimal, reproducible example that demonstrates the problem. Thanks!

dfm avatar Mar 21 '23 17:03 dfm

Same for me. Here an example:


import numpy as np
import matplotlib.pyplot as plt
import corner

# Generate data
n_samples = 10000
n_parameters = 3
samples = np.random.randn(n_samples, n_parameters)


# Generate the corner plot
fig = corner.corner(samples, 
                    axes_scale=['log','linear','log'],
                    show_titles=True)

plt.show()

Same thing if I just do axes_scale='log'

Screenshot 2024-05-27 at 3 32 55 PM

alessandropeca avatar May 27 '24 19:05 alessandropeca

@dfm -- i think this issue might be resolved by raising a value error if a user asks for log scales for a parameter with negative values.

An example where axes_scale works

The following snippet produces a corner with log-scaled axes: 1


import numpy as np
import corner
import arviz as az

# Generate data
n_samples = 10000
samples = az.from_dict({
    "log_a": np.random.lognormal(0, 1, n_samples),
    "linear_b": np.random.normal(0, 1, n_samples),
    "log_c": np.random.lognormal(0, 1, n_samples),
})

corner.corner(
    samples,
    axes_scale=['log', 'linear', 'log'],
    show_titles=True
).savefig("corner_plot.png")


Why @alessandropeca 's example does not yield log-scales

The samples are negative in @alessandropeca's example, leading to nans bins.

Using corner==2.2.2, @alessandropeca's example yields the following error:

ValueError: It looks like at least one of your sample columns have no dynamic range. 
You could try using the 'range' argument.

This is how the bins are created: https://github.com/dfm/corner.py/blob/2f2152bd2804ac4d4c7cee2c762cef3740bf4318/src/corner/core.py#L222

            bins_1d = np.logspace(
                np.log10(min(range[i])), np.log10(max(range[i])), n_bins_1d + 1
            )

The lower bin will be a nan.

avivajpeyi avatar Oct 23 '24 21:10 avivajpeyi