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

[FR] log transformed bins in histogram #348

Open
fchichorro opened this issue Apr 10, 2023 · 1 comment
Open

[FR] log transformed bins in histogram #348

fchichorro opened this issue Apr 10, 2023 · 1 comment

Comments

@fchichorro
Copy link

I want to create an histogram for a vector like this:

using UnicodePlots
using Random

Random.seed!(1234)
a = rand(1:5) .^ (0:0.1:5)
histogram(a)
                ┌                                        ┐
   [ 0.0,  5.0)   ┤████████████████████████████████████  24
   [ 5.0, 10.0)  ┤███████████████  10
   [10.0, 15.0) ┤█████████  6
   [15.0, 20.0) ┤██████  4
   [20.0, 25.0) ┤████▌ 3
   [25.0, 30.0) ┤████▌ 3
   [30.0, 35.0) ┤█▌ 1
                └                                        ┘
                                 Frequency

Since the variable is exponential, log transforming it would be more appropriate:

histogram(log10.(a))
              ┌                                        ┐
   [0.0, 0.5) ┤█████████████████████████████████████  8
   [0.5, 1.0) ┤████████████████████████████████▍ 7
   [1.0, 1.5) ┤████████████████████████████████▍ 7
   [1.5, 2.0) ┤████████████████████████████████▍ 7
   [2.0, 2.5) ┤█████████████████████████████████████  8
   [2.5, 3.0) ┤████████████████████████████████▍ 7
   [3.0, 3.5) ┤████████████████████████████████▍ 7
              └                                        ┘
                               Frequency

But I was wondering if there was a way to do it so I do not need to log transform the variable myself. Something that looked like this (notice the bin labels):

              ┌                                        ┐
   [10^0, 10^0.5)    ┤█████████████████████████████████████  8
   [10^0.5, 10^1.0) ┤████████████████████████████████▍ 7
   [10^1.0, 10^1.5) ┤████████████████████████████████▍ 7
   [10^1.5, 10^2.0) ┤████████████████████████████████▍ 7
   [10^2.0, 10^2.5) ┤█████████████████████████████████████  8
   [10^2.5, 10^3.0) ┤████████████████████████████████▍ 7
   [10^3.0, 10^3.5) ┤████████████████████████████████▍ 7
              └                                        ┘
                               Frequency

I tried it with

histogram(a, yscale=:log10)
histogram(a, yscale=x->log10(x))

Interestingly the plot was created as if the yscale argument was not set, which to me was misleading. I think this should either throw an error or the behaviour should be to create logarithmic bins?

This should also probably throw an error:

histogram(a, yscale=:hello)
@t-bltg
Copy link
Member

t-bltg commented Apr 10, 2023

Indeed this would be a great addition.

Horizontal histograms use barplots under the hood, so it's probably best to add an arbitrary scale support there first.

PRs welcome 🙂

@t-bltg t-bltg changed the title log transformed bins in histogram [FR] log transformed bins in histogram Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants