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

tech.tablesaw.plotly.api.Heatmap Maven / Gradle / Ivy

There is a newer version: 0.43.1
Show newest version
package tech.tablesaw.plotly.api;

import tech.tablesaw.api.Table;
import tech.tablesaw.columns.Column;
import tech.tablesaw.plotly.components.Figure;
import tech.tablesaw.plotly.components.Layout;
import tech.tablesaw.plotly.traces.HeatmapTrace;
import tech.tablesaw.util.DoubleArrays;

import java.util.List;

public class Heatmap {

    private Heatmap() {}

    public static Figure create(String title, Table table, String categoryCol1, String categoryCol2) {
        Layout layout = Layout.builder(title).build();

        Table counts = table.xTabCounts(categoryCol1, categoryCol2);
        counts = counts.dropRows(counts.rowCount() - 1);
        List> columns = counts.columns();
        columns.remove(counts.columnCount() - 1);
        Column yColumn = columns.remove(0);
        double[][] z = DoubleArrays.to2dArray(counts.numericColumns());

        Object[] x = counts.columnNames().toArray();
        Object[] y = yColumn.asObjectArray();
        HeatmapTrace trace = HeatmapTrace.builder(x, y, z).build();
        return new Figure(layout, trace);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy