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

Possible improvement of hplot.Ticks{N: 10} #629

Closed
rmadar opened this issue Apr 8, 2020 · 6 comments · Fixed by #632
Closed

Possible improvement of hplot.Ticks{N: 10} #629

rmadar opened this issue Apr 8, 2020 · 6 comments · Fixed by #632

Comments

@rmadar
Copy link
Member

rmadar commented Apr 8, 2020

On the example below, I show the default tick of gonum/v1/plot (left) and the output of hplot.Ticks{N: 10} command (right). While it seems to have the desired effect on the x-axis, it doesn't seem to be as nice for y-axis (int his particular example). If I understand correctly, N is supposed to be the maximum number of major ticks, and there is 0 major ticks on the right.

image

@sbinet
Copy link
Member

sbinet commented Apr 9, 2020

do you have a somewhat simple reproducer I could play with?

@rmadar
Copy link
Member Author

rmadar commented Apr 9, 2020

Yes, you can have a look at the test of https://github.com/rmadar/hplot-style .

To reproduce the problem, you just have to comment or not the line https://github.com/rmadar/hplot-style/blob/master/style/style.go#L58 and re-run the example.

@sbinet
Copy link
Member

sbinet commented Apr 9, 2020

yeah, it seems David's algorithm is a tad less robust than gonum/plot's.

playing a bit with gonum/plot's ticker (but allowing to change the default N=3 suggested ticks, I came up with this:
ticks

compared to the one with David's:
ticks_golden

and here's what your example plot would look like:
example_plot

except for the pathological case of an interval [0,1.2] (row=7 in the gallery of ticks), I would say it's not too shabby.
would do you think?

@rmadar
Copy link
Member Author

rmadar commented Apr 9, 2020

it seems David's algorithm is a tad less robust

Whaaat ??? ;-)

I think your proposal is really good! I was just wondering why the row 5 and 6 have the same ticks in your case while David's algorithm yields to different ticks (I am actually not sure what change from 1 row to another)

In any case, I would maybe propose to have a number formatting without decimals for raw 5 and 6 (if that's easy to do - I have no idea how these things work), i.e. 1000 instead of 1000.00.

Otherwise, it looks very good to me!

@sbinet
Copy link
Member

sbinet commented Apr 9, 2020

Whaaat ??? ;-)

don't tell him I said that.

what does change from row-to-row (besides the xmin/xmax) is the number of required rows:

I was just wondering why the row 5 and 6 have the same ticks

oops, forgot to change back the requested number of ticks...
I tried a couple of hours to understand the 1000/1000.00 behaviour to no avail.
what could be done is to optionally provide a string as a format (if empty, the automatically picked one from the underlying mechanism would be used.)
e.g.:

type Ticks struct {
    N int
    Fmt string // e.g. "%8.2f"
}

@rmadar
Copy link
Member Author

rmadar commented Apr 9, 2020

I like the idea of the formatting string to be more flexible. I think we can go for it and see in practice how (in)convenient this is. But I'd say it's a good move!

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

Successfully merging a pull request may close this issue.

2 participants