GiovineItalia / Gadfly.jl

Crafty statistical graphics for Julia.

Home Page:http://gadflyjl.org/stable/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrong x-axis upper limit with date ?

apraga opened this issue · comments

Hi,

With the following minimal example, I find the upper plot limit is higher than it should be, resulting in a lot of blank space :

d = DataFrame(date=[
    DateTime(2023,03,23),
    DateTime(2023,03,22),
    DateTime(2023,03,21),
    DateTime(2023,03,20),
    DateTime(2023,03,19),
    DateTime(2023,03,18),
    DateTime(2023,03,17),
    DateTime(2023,03,16),
    DateTime(2023,03,15),
    DateTime(2023,03,14)
],
              result= [0.37, 1.66, 0.1, 2.64, 0.6, 3.73, 0.74, 5.69, 1.82, 2.93])
plot(d, x=:date, y=:result)

image

Is there a way to correct the default behaviour ? Using maxvalue with scale.x_continous did not help. Thanks!

Coord.cartesian(xmax=...

or Scale.x_continuous[maxvalue=....

it's not a bug per se. there is an optimization algorithm which computes the bounds and number of ticks. ideally we need to figure out a way to hoist the parameters (ie granularity_weight, simplicity_weight, coverage_weight, and niceness_weight) into a user accessible function instead of just hard-coding defaults.

Using integer instead of date gives a result much more satisfying for the end-user:

d = DataFrame(date = [23, 22, 21, 20, 19, 18, 17, 16, 15, 14],
              result= [0.37, 1.66, 0.1, 2.64, 0.6, 3.73, 0.74, 5.69, 1.82, 2.93])
plot(d, x=:date, y=:result)

axis

Is it the expected behaviour that bounds are different for date and integers in this example ? Thanks !

a lot of changes were made to dates recently and there hasn't been a new release made to include them. try checking out master (with ] dev Gadfly) and see if the ticks are any better for you. i get the following plots on master for your two examples above:
Screenshot 2023-03-26 at 5 59 02 PM
Screenshot 2023-03-26 at 5 59 09 PM

Thanks for your quick answer ! It does fixes my issue, closing it now.