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

How to force y Axis to use floating point precision? #462

Open
parrotcar00 opened this issue Jan 26, 2025 · 1 comment
Open

How to force y Axis to use floating point precision? #462

parrotcar00 opened this issue Jan 26, 2025 · 1 comment

Comments

@parrotcar00
Copy link

I used this code from kandy examples:

val years = listOf(1, 2, 3, 4, 5)
val cost = listOf(62.7, 39.3, 72.1, 73.7, 68.5)

plot {
    line {
        x(years)
        y(cost)
        type = LineType.SOLID
    }
}

And when you hover over the resultant plot values, we see y axis labels that correctly show values with decimal point like 62.7, 72.1 etc.

Image

But if I use this dataset instead:

val years2 = listOf(1, 2, 3, 4, 5)
val cost2 = listOf(95.0, 2.2, 3.3, 4.4, 5.5)

plot {
    line {
        x(years2)
        y(cost2)
        type = LineType.SOLID
    }
}

I get a plot where all y values are rounded off to the nearest integer. I don't understand what is causing this and how to force y axis to be of Double type.

Image

How do I force y axis to use decimal values?

@AndreiKingsley
Copy link
Collaborator

Hi! It's a Lets-Plot behaviour, tooltip values are automatically formatted based on the data range, which can sometimes result in rounding. However, you can manually adjust the format. We are still working on refining and stabilizing the API for customizing tooltips, but for now, you can solve this issue as follows:

val years2 = listOf(1, 2, 3, 4, 5)
val cost2 = listOf(95.0, 2.2, 3.3, 4.4, 5.5)

plot {
    line {
        x(years2)
        // add id for this data source
        y(cost2, "cost2")
        // manually add tooltips with `cost2` and adjust format
        tooltips("cost2", formats = mapOf("cost2" to ".2f"))
        type = LineType.SOLID
    }
}

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

No branches or pull requests

2 participants