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

Support for multiple Y axes #92

Open
luispollo opened this issue Mar 31, 2023 · 1 comment
Open

Support for multiple Y axes #92

luispollo opened this issue Mar 31, 2023 · 1 comment
Labels
feature New feature or request
Milestone

Comments

@luispollo
Copy link

Other variants of Plotly (JS, Python) support plotting traces on multiple Y axes. It'd be great if that feature was ported to the Kotlin wrapper.

@SPC-code
Copy link
Contributor

I did not know about that feature. I will add it to new release. For now, you can use custom fields like this:

import space.kscience.dataforge.meta.set
import space.kscience.dataforge.meta.spec
import space.kscience.dataforge.names.asName
import space.kscience.plotly.Plotly
import space.kscience.plotly.layout
import space.kscience.plotly.makeFile
import space.kscience.plotly.models.Axis
import space.kscience.plotly.models.Layout
import space.kscience.plotly.scatter


fun Layout.yaxis(index: Int, block: Axis.()->Unit){
    require(index>=2){"Secondary axis index must be 2 or more"}
    val axisSpec by spec(Axis,"yaxis$index".asName())
    axisSpec.apply(block)
}

fun main() {
    Plotly.plot {

        scatter{
            x(1, 2, 3)
            y(40, 50, 60)
            name = "yaxis data"
        }

        scatter{
            x(2, 3, 4)
            y(4, 5, 6)
            name = "yaxis2 data"
            set("yaxis","y2")
        }

        layout {
            title = "Double Y Axis Example"
            yaxis {
                title = "yaxis title"
            }
            yaxis(2) {
                title {
                    text = "yaxis2 title"
                    font {
                        color("rgb(148, 103, 189)")
                    }
                }
                tickfont {
                    color("rgb(148, 103, 189)")
                }
                set("overlaying", "y")
                set("side","right")
            }
        }
    }.makeFile()
}

@SPC-code SPC-code added the feature New feature or request label Mar 31, 2023
@SPC-code SPC-code added this to the 0.5.3 milestone Mar 31, 2023
@SPC-code SPC-code mentioned this issue Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants