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

plot_dot #2031

Closed
canyon289 opened this issue May 15, 2022 · 4 comments · Fixed by #2032
Closed

plot_dot #2031

canyon289 opened this issue May 15, 2022 · 4 comments · Fixed by #2032
Labels

Comments

@canyon289
Copy link
Member

canyon289 commented May 15, 2022

Describe the bug
plotdot fig size doesn't behave the way I expect, in that when I set figsize in an axes that triple a previous one its not triple the size. There also are some minor bugs where the dots seem to be overlapping some

To Reproduce

samples = stats.beta(2,2).rvs(100)

width = 10
fig, ax = plt.subplots(figsize=(width, 10))
az.plot_dot(samples, ax=ax)
ax.set_title(f"Width: {width}")
ax.set_xlim(0,1)

Then try this, but see that figure is not three times the width

width = 30
fig, ax = plt.subplots(figsize=(width, 10))
az.plot_dot(samples, ax=ax)
ax.set_title(f"Width: {width}")
ax.set_xlim(0,1)

image
image

Expected behavior
Figsize from plt.subplots is respected

Additional context
Arviz '0.12.0'

@sethaxen
Copy link
Member

The overlapping stacks appears to be an issue with wilkinson_algorithm:

>>> values = stats.beta(2,2).rvs(100)

>>> values.sort()

>>> binwidth = 0.07

>>> stack_locs, stack_count = az.plots.dotplot.wilkinson_algorithm(values, binwidth)

>>> np.diff(stack_locs) > binwidth  # should all be True
array([ True,  True,  True,  True, False,  True,  True,  True,  True,
        True,  True, False])

@sethaxen
Copy link
Member

Ah, okay, overlapping stacks is actually not a bug. This is possible and intended behavior. e.g. suppose we have the data [1, 1.9, 2.1, 2.1, 3.2] and use a binwidth=1. Then the bins would be [[1, 1.9], [2.1, 2.1], [3.2]], the bin centers would be [1.45, 2.1, 3.2], and the bin edges would be [[0.95, 1.95], [1.6, 2.6], [2.7, 3.7]], so the first and second stacks will overlap. Not allowing overlap would require the first or second stack be further from the underlying data.

This is how ggplot2::geom_dotplot behaves:

> x <- c(1, 1.9, 2.1, 2.1, 3.2)
> df <- data.frame(x)
> ggplot(df, aes(x=x)) + geom_dotplot(binwidth=1)

tmp

@ahartikainen
Copy link
Contributor

Good to know this. Then PR should only fix aspect

@canyon289
Copy link
Member Author

Wow what an indepth analysis. Thanks @sethaxen

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

Successfully merging a pull request may close this issue.

3 participants