All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.danielTucano.matplotlib.Axes.kt Maven / Gradle / Ivy

package io.github.danielTucano.matplotlib

import io.github.danielTucano.extensions.*
import io.github.danielTucano.matplotlib.Line2D.Companion.line2DNumber
import io.github.danielTucano.matplotlib.Quiver.Companion.quiverNumber
import io.github.danielTucano.matplotlib.np.NPVar
import io.github.danielTucano.matplotlib.pyplot.GridAxisOptions
import io.github.danielTucano.matplotlib.pyplot.GridWhichOptions
import io.github.danielTucano.python.PythonScriptBuilder
import java.awt.Color

/**
 * Axes class methods signatures from io.github.danieltucano.matplotlib
 */
interface Axes : AxesBase {

    override val variableName: String

    companion object {
        internal var axesNumber: Int = 0
            get() {
                field++
                return field
            }
            private set
    }

    fun plot(
        x: List? = null,
        y: List,
        fmt: String? = null,
        kwargs: Map? = null
    ): Line2D {
        return object : Line2D {
            override val variableName: String = "line2D_$line2DNumber"

            init {
                PythonScriptBuilder.addCommand(
                    "$variableName = ${[email protected]}.plot(" +
                            "${x.toPythonNumberArrayStringOrEmpty()}${x.emptyIfNullOrComma()}" +
                            "${y.toPythonNumberArrayStringOrEmpty()}${fmt.emptyIfNullOrComma()}" +
                            "${fmt.toPythonStringQuotedOrEmpty()}${kwargs.emptyIfNullOrComma()}" +
                            kwargs.toKwargPythonStringOrEmpty() +
                            ")"
                )
            }
        }
    }

    fun grid(
        b: Boolean? = null,
        which: GridWhichOptions = GridWhichOptions.major,
        axis: GridAxisOptions = GridAxisOptions.both
    ) {
        PythonScriptBuilder.addCommand("$variableName.grid(b=${b.toPythonBooleanOrNone()},which=${which.toPythonStringQuotedOrEmpty()},axis=${axis.toPythonStringQuotedOrEmpty()})")
    }

    fun scatter(
        x: List,
        y: List,
        s: Double? = null,
        c: String? = null,
        marker: String? = null,
        cmap: String? = null,
        norm: String? = null,
        vmin: Double? = null,
        vmax: Double? = null,
        alpha: Double? = null,
        linewidths: Double? = null,
        edgecolors: Color? = null,
        plotnonfinite: Boolean = false
    ) {
        PythonScriptBuilder.addCommand(
            "$variableName.scatter(" +
                    "${x.toPythonNumberArrayStringOrEmpty()}," +
                    "${y.toPythonNumberArrayStringOrEmpty()}," +
                    "s=${s.toPythonStringOrNone()}," +
                    "c=${c.toPythonStringQuotedOrNone()}," +
                    "marker=${marker.toPythonStringOrNone()}," +
                    "cmap=${cmap.toPythonStringQuotedOrNone()}," +
                    "norm=${norm.toPythonStringOrNone()}," +
                    "vmin=${vmin.toPythonStringOrNone()}," +
                    "vmax=${vmax.toPythonStringOrNone()}," +
                    "alpha=${alpha.toPythonStringOrNone()}," +
                    "linewidths=${linewidths.toPythonStringOrNone()}," +
                    "edgecolors=${edgecolors.toPythonTupleStringOrNone()}," +
                    "plotnonfinite=${plotnonfinite.toPythonBooleanOrNone()}" +
                    ")"
        )
    }

    fun quiver(
        xValues: NPVar,
        yValues: NPVar,
        uValues: NPVar,
        vValues: NPVar,
        units: QuiverUnitsOptions? = QuiverUnitsOptions.width,
        angles: QuiverAnglesOptions? = null,
        scale: Double? = null,
        scale_units: QuiverScaleUnitsOptions? = null,
        width: Double? = null,
        headwidth: Double = 3.0,
        headlength: Double = 5.0,
        headaxislength: Double = 4.5,
        minshaft: Double = 1.0,
        minlength: Double = 1.0,
        pivot: QuiverPivotOptions = QuiverPivotOptions.tail,
        color: List = listOf(Color.BLACK),
        zorder: Double = 3.0
    ): Quiver {
        return object : Quiver {
            override val variableName: String = "quiver_$quiverNumber"

            init {
                PythonScriptBuilder.addCommand(
                    "${this.variableName} = ${[email protected]}.quiver(" +
                            "${xValues.variableName}," +
                            "${yValues.variableName}," +
                            "${uValues.variableName}," +
                            "${vValues.variableName}," +
                            "units=${units.toPythonStringQuotedOrNone()}," +
                            "angles=${angles.toPythonStringQuotedOrNone()}," +
                            "scale=${scale.toPythonStringOrNone()}," +
                            "scale_units=${scale_units.toPythonStringQuotedOrNone()}," +
                            "width=${width.toPythonStringOrNone()}," +
                            "headwidth=${headwidth.toPythonStringOrNone()}," +
                            "headlength=${headlength.toPythonStringOrNone()}," +
                            "headaxislength=${headaxislength.toPythonStringOrNone()}," +
                            "minshaft=${minshaft.toPythonStringOrNone()}," +
                            "minlength=${minlength.toPythonStringOrNone()}," +
                            "pivot=${pivot.toPythonStringQuotedOrNone()}," +
                            "color=${color.toPythonColorTupleArrayOrNone()}," +
                            "zorder=${zorder.toPythonStringOrNone()}" +
                            ")"
                )
            }
        }
    }

    fun quiver(
        xValues: List,
        yValues: List,
        uValues: List,
        vValues: List,
        units: QuiverUnitsOptions? = QuiverUnitsOptions.width,
        angles: QuiverAnglesOptions? = null,
        scale: Double? = null,
        scale_units: QuiverScaleUnitsOptions? = null,
        width: Double? = null,
        headwidth: Double = 3.0,
        headlength: Double = 5.0,
        headaxislength: Double = 4.5,
        minshaft: Double = 1.0,
        minlength: Double = 1.0,
        pivot: QuiverPivotOptions = QuiverPivotOptions.tail,
        color: List = listOf(Color.BLACK),
        zorder: Double = 3.0
    ): Quiver {
        return object : Quiver {
            override val variableName: String = "quiver_$quiverNumber"
            init {
                PythonScriptBuilder.addCommand(
                    "${this.variableName} = ${[email protected]}.quiver(" +
                            "${xValues.toPythonNumberArrayStringOrEmpty()}," +
                            "${yValues.toPythonNumberArrayStringOrEmpty()}," +
                            "${uValues.toPythonNumberArrayStringOrEmpty()}," +
                            "${vValues.toPythonNumberArrayStringOrEmpty()}," +
                            "units=${units.toPythonStringQuotedOrNone()}," +
                            "angles=${angles.toPythonStringQuotedOrNone()}," +
                            "scale=${scale.toPythonStringOrNone()}," +
                            "scale_units=${scale_units.toPythonStringQuotedOrNone()}," +
                            "width=${width.toPythonStringOrNone()}," +
                            "headwidth=${headwidth.toPythonStringOrNone()}," +
                            "headlength=${headlength.toPythonStringOrNone()}," +
                            "headaxislength=${headaxislength.toPythonStringOrNone()}," +
                            "minshaft=${minshaft.toPythonStringOrNone()}," +
                            "minlength=${minlength.toPythonStringOrNone()}," +
                            "pivot=${pivot.toPythonStringQuotedOrNone()}," +
                            "color=${color.toPythonColorTupleArrayOrNone()}," +
                            "zorder=${zorder.toPythonStringOrNone()}" +
                            ")"
                )
            }
        }
    }

    enum class QuiverUnitsOptions { width, height, dots, inces, x, y, xy }

    enum class QuiverAnglesOptions { uv, xy }

    enum class QuiverScaleUnitsOptions { wigth, height, dots, inches, x, y, xy }

    enum class QuiverPivotOptions { tail, middle, tip }

    fun set_title(label: String = "", loc: TitleLocationOptions? = null, pad: Float? = null, y: Float? = null) {
        PythonScriptBuilder.addCommand(
            "$variableName.set_title(" +
                    "${label.toPythonStringQuotedOrEmpty()}," +
                    "loc=${loc.toPythonStringOrNone()}," +
                    "pad=${pad.toPythonStringOrNone()}," +
                    "y=${y.toPythonStringOrNone()}" +
                    ")"
        )
    }

    enum class TitleLocationOptions { center, left, right }


    fun legend() {
        PythonScriptBuilder.addCommand("$variableName.legend()")
    }

    fun legend(legends: List) {
        PythonScriptBuilder.addCommand(
            "$variableName.legend([${
                legends.joinToString(
                    separator = ",",
                    prefix = "'",
                    postfix = "'"
                )
            }])"
        )
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy