Search in sources :

Example 6 with Figure

use of tech.tablesaw.plotly.components.Figure in project tablesaw by jtablesaw.

the class TukeyMeanDifferencePlot method create.

/**
 * Returns a figure containing a QQ Plot describing the differences between the distribution of
 * values in the columns of interest
 *
 * @param title A title for the plot
 * @param measure The measure being compared on the plot (e.g "inches" or "height in inches"
 * @param xData The data to plot on the x Axis
 * @param yData The data to plot on the y Axis
 * @return A quantile plot
 */
public static Figure create(String title, String measure, double[] xData, double[] yData) {
    Preconditions.checkArgument(xData.length != 0, "x Data array is empty");
    Preconditions.checkArgument(yData.length != 0, "x Data array is empty");
    if (xData.length != yData.length) {
        double[] interpolatedData;
        if (xData.length < yData.length) {
            interpolatedData = interpolate(yData, xData.length);
            yData = interpolatedData;
        } else {
            interpolatedData = interpolate(xData, yData.length);
            xData = interpolatedData;
        }
    }
    Arrays.sort(xData);
    Arrays.sort(yData);
    double[] averagePoints = new double[xData.length];
    double[] differencePoints = new double[xData.length];
    for (int i = 0; i < xData.length; i++) {
        averagePoints[i] = (xData[i] + yData[i]) / 2.0;
        differencePoints[i] = (xData[i] - yData[i]);
    }
    double xMin = StatUtils.min(xData);
    double xMax = StatUtils.max(xData);
    double[] zeroLineX = { xMin, xMax };
    double[] zeroLineY = { 0, 0 };
    // Draw the line indicating equal distributions (this is zero in this plot)
    ScatterTrace trace1 = ScatterTrace.builder(zeroLineX, zeroLineY).mode(ScatterTrace.Mode.LINE).name("y = x").build();
    // Draw the actual data points
    ScatterTrace trace2 = ScatterTrace.builder(averagePoints, differencePoints).name("mean x difference").build();
    Layout layout = Layout.builder().title(title).xAxis(Axis.builder().title("mean (" + measure + ")").build()).yAxis(Axis.builder().title("difference (" + measure + ")").build()).height(700).width(900).build();
    return new Figure(layout, trace1, trace2);
}
Also used : Layout(tech.tablesaw.plotly.components.Layout) ScatterTrace(tech.tablesaw.plotly.traces.ScatterTrace) Figure(tech.tablesaw.plotly.components.Figure)

Example 7 with Figure

use of tech.tablesaw.plotly.components.Figure in project tablesaw by jtablesaw.

the class ViolinPlot method create.

public static Figure create(String title, Table table, String groupingColumn, String numericColumn, boolean showBoxPlot, boolean showMeanLine) {
    Layout layout = Layout.builder().title(title).height(HEIGHT).width(WIDTH).build();
    ViolinTrace trace = ViolinTrace.builder(table.categoricalColumn(groupingColumn), table.nCol(numericColumn)).boxPlot(showBoxPlot).meanLine(showMeanLine).build();
    return new Figure(layout, trace);
}
Also used : Layout(tech.tablesaw.plotly.components.Layout) ViolinTrace(tech.tablesaw.plotly.traces.ViolinTrace) Figure(tech.tablesaw.plotly.components.Figure)

Example 8 with Figure

use of tech.tablesaw.plotly.components.Figure in project tablesaw by jtablesaw.

the class Heatmap method create.

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<Column<?>> 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);
}
Also used : Table(tech.tablesaw.api.Table) Layout(tech.tablesaw.plotly.components.Layout) Column(tech.tablesaw.columns.Column) HeatmapTrace(tech.tablesaw.plotly.traces.HeatmapTrace) Figure(tech.tablesaw.plotly.components.Figure)

Example 9 with Figure

use of tech.tablesaw.plotly.components.Figure in project tablesaw by jtablesaw.

the class PiePlot method create.

public static Figure create(String title, Table table, String groupColName, String numberColName) {
    Layout layout = Layout.builder(title).build();
    PieTrace trace = PieTrace.builder(table.column(groupColName), table.numberColumn(numberColName)).showLegend(true).build();
    return new Figure(layout, trace);
}
Also used : PieTrace(tech.tablesaw.plotly.traces.PieTrace) Layout(tech.tablesaw.plotly.components.Layout) Figure(tech.tablesaw.plotly.components.Figure)

Example 10 with Figure

use of tech.tablesaw.plotly.components.Figure in project tablesaw by jtablesaw.

the class PricePlot method create.

public static Figure create(String title, Table table, String xCol, String openCol, String highCol, String lowCol, String closeCol, String plotType) {
    Layout layout = Layout.builder(title, xCol).build();
    Column<?> x = table.column(xCol);
    NumericColumn<?> open = table.numberColumn(openCol);
    NumericColumn<?> high = table.numberColumn(highCol);
    NumericColumn<?> low = table.numberColumn(lowCol);
    NumericColumn<?> close = table.numberColumn(closeCol);
    ScatterTrace trace;
    if (x.type() == ColumnType.LOCAL_DATE) {
        trace = ScatterTrace.builder(table.dateColumn(xCol), open, high, low, close).type(plotType).build();
    } else if (x.type() == ColumnType.LOCAL_DATE_TIME) {
        trace = ScatterTrace.builder(table.dateTimeColumn(xCol), open, high, low, close).type(plotType).build();
    } else if (x.type() == ColumnType.INSTANT) {
        trace = ScatterTrace.builder(table.instantColumn(xCol), open, high, low, close).type(plotType).build();
    } else {
        throw new IllegalArgumentException("Column containing data for the X-Axis must be of type INSTANT, LOCAL_DATE, or LOCAL_DATE_TIME");
    }
    return new Figure(layout, trace);
}
Also used : Layout(tech.tablesaw.plotly.components.Layout) ScatterTrace(tech.tablesaw.plotly.traces.ScatterTrace) Figure(tech.tablesaw.plotly.components.Figure)

Aggregations

Figure (tech.tablesaw.plotly.components.Figure)92 Layout (tech.tablesaw.plotly.components.Layout)72 ScatterTrace (tech.tablesaw.plotly.traces.ScatterTrace)53 Table (tech.tablesaw.api.Table)35 Test (org.junit.jupiter.api.Test)20 Trace (tech.tablesaw.plotly.traces.Trace)20 BarTrace (tech.tablesaw.plotly.traces.BarTrace)9 HistogramTrace (tech.tablesaw.plotly.traces.HistogramTrace)8 IntColumn (tech.tablesaw.api.IntColumn)7 File (java.io.File)6 TableSliceGroup (tech.tablesaw.table.TableSliceGroup)6 Marker (tech.tablesaw.plotly.components.Marker)4 Scatter3DTrace (tech.tablesaw.plotly.traces.Scatter3DTrace)4 ArrayList (java.util.ArrayList)3 Page (tech.tablesaw.plotly.components.Page)3 BoxTrace (tech.tablesaw.plotly.traces.BoxTrace)3 PieTrace (tech.tablesaw.plotly.traces.PieTrace)3 ViolinTrace (tech.tablesaw.plotly.traces.ViolinTrace)3 StringColumn (tech.tablesaw.api.StringColumn)2 Column (tech.tablesaw.columns.Column)2