Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

axes_scale argument does not work? #222

Open
anderss3 opened this issue Mar 18, 2023 · 3 comments
Open

axes_scale argument does not work? #222

anderss3 opened this issue Mar 18, 2023 · 3 comments

Comments

@anderss3
Copy link

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.

@dfm
Copy link
Owner

dfm commented Mar 21, 2023

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

@alessandropeca
Copy link

alessandropeca commented May 27, 2024

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

@avivajpeyi
Copy link
Contributor

avivajpeyi commented Oct 23, 2024

@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:

elif axes_scale[i] == "log":

            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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants