kandy 0.7.0 Help

Getting Started

You can utilize Kandy both in Kotlin projects and in interactive editors. For detailed instructions, refer to the respective pages:

Getting Kandy

How to Install Kotlin Notebook?

You can find detailed instructions here.

  1. Install IntelliJ IDEA Ultimate if you don't already have it.

  2. Open your IDE and press Cmd+comma to open the IDE settings.

  3. Select Plugins from the menu and install the Kotlin Notebook plugin.

  4. Click Ok to apply the changes and restart your IDE if prompted.

  5. Create a new Kotlin Notebook file.

  6. Run this cell:

    %use kandy // If you are using dataframe as data %use dataframe

Congratulations, you now have access to the Kandy library in Kotlin Notebook.

How to Use Datalore?

You can find detailed instructions here.

  1. Open Datalore.

  2. Register if you don't have an account.

  3. Create a new notebook.

  4. Select the Kotlin Kernel.

  5. Run this cell:

    %use kandy // If you are using dataframe as data %use dataframe

Congratulations, you now have access to the Kandy library in Datalore.

How to Install Jupyter with Kotlin?

You can find detailed instructions here.

  1. Install Jupyter.

  2. Install the Kotlin Kernel using one of the following methods:

    pip install kotlin-jupyter-kernel
    conda install -c jetbrains kotlin-jupyter-kernel
  3. Run Jupyter by executing the following command in the terminal:

    jupyter notebook
  4. Create a new notebook by selecting the Kotlin kernel.

  5. Run this cell in the notebook:

    %use kandy // If you are using dataframe as data %use dataframe

Congratulations, you now have access to the Kandy library in Jupyter Notebook.

Gradle Configuration

You can find detailed instructions here.

  1. Create a JVM project with Kotlin in your IDE.

  2. Add the Kandy dependency to your build.gradle.kts file:

    dependencies { implementation("org.jetbrains.kotlinx:kandy-lets-plot:0.7.0") }

Congratulations, you now have access to the Kandy library in your Kotlin project.

Plotting a Simple Example

Let's create data that will be used to construct the plot. This data will represent the average annual temperatures in various cities. When working in interactive notebooks, it is advisable to divide the data creation and plot construction into two separate cells. This approach ensures that extension properties are generated for our columns in the DataFrame, allowing us to reference them easily.

First, create a DataFrame containing data on the average temperatures in different cities as follows:

// Create a DataFrame with data on average temperatures in various cities val averageTemperature = dataFrameOf( "city" to listOf("New York", "London", "Berlin", "Yerevan", "Tokyo"), "average temperature" to listOf(12.5, 11.0, 9.6, 11.5, 16.0) )

Next, construct a simple plot using the data from the DataFrame:

// Construct a plot using the data from the DataFrame averageTemperature.plot { // Add bars to the plot // Each bar represents the average temperature in a city bars { x(city) // Set the cities' data on the X-axis y(`average temperature`) { // Set the temperatures' data on the Y-axis axis.name = "Average Temperature (°C)" // Assign a name to the Y-axis } } // Set the title of the plot layout.title = "Kandy Getting Started Example" }
Kandy Getting Started Example

This supplementary schema outlines the key elements of Kandy's DSL, providing a quick reference to assist you in building your visualizations.

For more examples, please see the Examples section.

Last modified: 30 January 2024