Search in sources :

Example 26 with Figure

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

the class MultiPlotExample method main.

public static void main(String[] args) throws Exception {
    /*
    Preliminaries:
    1. Get a table
    2. Split the data into two tables, one for each league
    3. Get the columns we're going to use in the plot as x1, y1, x2, y2
    4. Create a layout for each plot
    5. Create the traces for each plot
    6. Build a Figure for each plot from the layout and trace
    7. Create an HTML page as a string
    8. Write the string to a file
    9. Open the default desktop Web browser on the file so you can see it
    */
    // 1. Get a table
    Table baseball = Table.read().csv("../data/baseball.csv");
    // 2. Split the data into two tables, one for each league
    List<Table> leagueTables = baseball.splitOn("league").asTableList();
    Table league1 = leagueTables.get(0);
    Table league2 = leagueTables.get(1);
    // 3. Get the columns we're going to use in the plot as x1, y1, x2, y2
    NumericColumn<?> x1 = league1.nCol("BA");
    NumericColumn<?> y1 = league1.nCol("W");
    NumericColumn<?> x2 = league2.nCol("BA");
    NumericColumn<?> y2 = league2.nCol("W");
    // 4. Create a layout for each plot
    Layout layout1 = Layout.builder().title("American League Wins vs BA").xAxis(Axis.builder().title("Batting Average").build()).yAxis(Axis.builder().title("Wins").build()).build();
    Layout layout2 = Layout.builder().title("National League Wins vs BA").xAxis(Axis.builder().title("Batting Average").build()).yAxis(Axis.builder().title("Wins").build()).build();
    // 5. Create the traces for each plot
    Trace trace1 = ScatterTrace.builder(x1, y1).build();
    Trace trace2 = ScatterTrace.builder(x2, y2).build();
    // 6. Build a Figure for each plot from the layout and trace
    Figure figure1 = new Figure(layout1, trace1);
    Figure figure2 = new Figure(layout2, trace2);
    // 7. Create an HTML page as a string
    String divName1 = "plot1";
    String divName2 = "plot2";
    String page = makePage(figure1, figure2, divName1, divName2);
// 8. Write the string to a file
// uncomment to try (see imports also)
/*
        File outputFile = Paths.get("multiplot.html").toFile();
        try {
          try (FileWriter fileWriter = new FileWriter(outputFile)) {
            fileWriter.write(page);
          }
        } catch (IOException e) {
          e.printStackTrace();
        }
    */
// 9. Open the default desktop Web browser on the file so you can see it
// uncomment to try
// new Browser().browse(outputFile);
}
Also used : Trace(tech.tablesaw.plotly.traces.Trace) ScatterTrace(tech.tablesaw.plotly.traces.ScatterTrace) Table(tech.tablesaw.api.Table) Layout(tech.tablesaw.plotly.components.Layout) Figure(tech.tablesaw.plotly.components.Figure)

Example 27 with Figure

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

the class ParetoExample method main.

public static void main(String[] args) throws Exception {
    Table table = Table.read().csv("../data/tornadoes_1950-2014.csv");
    table = table.where(table.numberColumn("Fatalities").isGreaterThan(3));
    Table t2 = table.summarize("fatalities", sum).by("State");
    t2 = t2.sortDescendingOn(t2.column(1).name());
    Layout layout = Layout.builder().title("Tornado Fatalities by State").build();
    BarTrace trace = BarTrace.builder(t2.categoricalColumn(0), t2.numberColumn(1)).build();
    Plot.show(new Figure(layout, trace));
}
Also used : Table(tech.tablesaw.api.Table) Layout(tech.tablesaw.plotly.components.Layout) BarTrace(tech.tablesaw.plotly.traces.BarTrace) Figure(tech.tablesaw.plotly.components.Figure)

Example 28 with Figure

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

the class PieExample method main.

public static void main(String[] args) throws Exception {
    Table table = Table.read().csv("../data/tornadoes_1950-2014.csv");
    Table t2 = table.countBy(table.categoricalColumn("Scale"));
    PieTrace trace = PieTrace.builder(t2.categoricalColumn("Category"), t2.numberColumn("Count")).build();
    Layout layout = Layout.builder().title("Total fatalities by scale").build();
    Plot.show(new Figure(layout, trace));
}
Also used : Table(tech.tablesaw.api.Table) PieTrace(tech.tablesaw.plotly.traces.PieTrace) Layout(tech.tablesaw.plotly.components.Layout) Figure(tech.tablesaw.plotly.components.Figure)

Example 29 with Figure

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

the class BubbleTest method showScatter.

@Test
public void showScatter() {
    ScatterTrace trace = ScatterTrace.builder(x, y).mode(ScatterTrace.Mode.MARKERS).marker(Marker.builder().size(size).colorScale(Marker.Palette.CIVIDIS).opacity(.5).showScale(true).symbol(Symbol.DIAMOND_TALL).build()).build();
    Plot.show(new Figure(trace));
}
Also used : ScatterTrace(tech.tablesaw.plotly.traces.ScatterTrace) Figure(tech.tablesaw.plotly.components.Figure) Test(org.junit.jupiter.api.Test)

Example 30 with Figure

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

the class ContourTest method testContourTrace.

@Test
public void testContourTrace() {
    ContourTrace trace = ContourTrace.builder(x, y, z).build();
    Figure figure = new Figure(trace);
    Plot.show(figure);
}
Also used : ContourTrace(tech.tablesaw.plotly.traces.ContourTrace) Figure(tech.tablesaw.plotly.components.Figure) Test(org.junit.jupiter.api.Test)

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