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

add smart fillto to enable logscale y-axis histogram barplot #3004

Merged
merged 11 commits into from
Jul 14, 2023

Conversation

Moelf
Copy link
Contributor

@Moelf Moelf commented Jun 13, 2023

Fix #3000

This implements what's suggested on Slack, namely, detect if transformation is one of the dangerous logs (example of non-dangerous log is Makie.pseudolog10), if so, use the minimal non zero value divided by 2 as the "bottom" to avoid illegal transformation 0 -> -Inf when applying the log.

Some examples that used to error but now works:

using CairoMakie

a = "/tmp/jl_k9M7ELsL2h.png"

save(a, hist(randn(10^6); axis=(; yscale=log10)))

save(a, hist(randn(10^6); axis=(; yscale=log2)))

save(a, hist(filter!(x-> x<0 || x > 1.5, randn(10^6)); axis=(; yscale=log10)))

image

image
image

@asinghvi17 asinghvi17 added enhancement Feature requests and enhancements Makie Backend independent issues (Makie core) labels Jun 13, 2023
@Moelf
Copy link
Contributor Author

Moelf commented Jun 13, 2023

(should maybe also add a test?)

@asinghvi17
Copy link
Member

asinghvi17 commented Jun 13, 2023

Ideally, test + example in the barplot page. The test can be added here:

https://github.com/Moelf/Makie.jl/blob/log_yscale_barplot_smart_fillto/ReferenceTests/src/tests/examples2d.jl

@Moelf
Copy link
Contributor Author

Moelf commented Jun 13, 2023

when you say example do you mean in the docs? I don't think we need that right?

src/basic_recipes/barplot.jl Show resolved Hide resolved
src/basic_recipes/barplot.jl Outdated Show resolved Hide resolved
@jkrumbiegel
Copy link
Member

example do you mean in the docs? I don't think we need that right?

yes a docs example would be good because we want to explain every single attribute visually in the long run. And the visual effect of fillto = automatic would have to be shown

@jkrumbiegel
Copy link
Member

we could also think about a drop_zeros attribute which would remove the bars at zero. This makes no difference for linear scale because you can't see them anyway, but for log scale it would make an otherwise invalid plot valid.

@Moelf
Copy link
Contributor Author

Moelf commented Jun 14, 2023

I would say drop zero is not needed because in both cases it should be invisible, that seems to be the only reasonable behavior

@jkrumbiegel
Copy link
Member

jkrumbiegel commented Jun 14, 2023

how would a value of 0 be invisible in the log scale case? Or do you mean you would always drop zeros so no setting needed

@Moelf
Copy link
Contributor Author

Moelf commented Jun 14, 2023

See the third example in op. I'm saying we always drop zero and it's already implemented, but maybe there's a better way to implement it

@Moelf
Copy link
Contributor Author

Moelf commented Jun 14, 2023

the last commit makes x-scale work too:

barplot(
           tbl.x, tbl.height,
           dodge = tbl.grp,
           color = tbl.grp,
           bar_labels = :y,
           axis = (xticks = (1:3, ["left", "middle", "right"]),
                   title = "Dodged bars horizontal with labels", xscale=log10), # <---------------------------
           colormap = [:red, :green, :blue],
           color_over_background=:red,
           color_over_bar=:white,
           flip_labels_at=0.85,
           direction=:x,
       );

this used to error, but now:
image

@Moelf
Copy link
Contributor Author

Moelf commented Jun 16, 2023

is this ready? I don't know what example I should add, fillto itself is documented in the barplot page pretty well

@Moelf
Copy link
Contributor Author

Moelf commented Jul 7, 2023

this seems ready 👀

@SimonDanisch
Copy link
Member

@jkrumbiegel wanted to do a final review before merging

@Moelf
Copy link
Contributor Author

Moelf commented Jul 11, 2023

franklin error seems unrelated

@SimonDanisch
Copy link
Member

Hm, a new Franklin version was released just now: https://github.com/tlienart/Franklin.jl/releases/tag/v0.10.86
I guess that's most likely the cause?

@Moelf
Copy link
Contributor Author

Moelf commented Jul 11, 2023

yeah I think so, this PR didn't touch the the slide grid markdown

@Moelf
Copy link
Contributor Author

Moelf commented Jul 13, 2023

Looks like it Passed?

Copy link
Member

@jkrumbiegel jkrumbiegel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made some small changes to the test to exercise the x direction code, too. I think this is good to go now. I haven't tested out all combinations of switching back and forth in GLMakie, but it looked like we easily get limit errors that way which are not really related to the recipe, rather to the limit update code and when what value is updated. So not relevant here.

There should be a docs example added at some point, but before I spend time doing that in the current format, I'd rather wait until we switch the plotting functions to direct attribute docs like we have for Blocks. Shouldn't block this right now.

@SimonDanisch SimonDanisch reopened this Jul 14, 2023
@jkrumbiegel jkrumbiegel merged commit 30687f0 into MakieOrg:master Jul 14, 2023
25 of 26 checks passed
@Moelf Moelf deleted the log_yscale_barplot_smart_fillto branch July 14, 2023 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature requests and enhancements (log) scale Makie Backend independent issues (Makie core)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Log scale broken for histograms
5 participants