Search in sources :

Example 1 with BarTrace

use of tech.tablesaw.plotly.traces.BarTrace 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 2 with BarTrace

use of tech.tablesaw.plotly.traces.BarTrace in project tablesaw by jtablesaw.

the class PageTest method testCustomPlotlyJsLocation.

@Test
public void testCustomPlotlyJsLocation() {
    BarTrace trace = BarTrace.builder(x, y).build();
    String location = this.getClass().getResource(this.getClass().getSimpleName() + ".class").toString();
    Page page = Page.pageBuilder(new Figure(trace), "plot").plotlyJsLocation(location).build();
    String html = page.asJavascript();
    assertTrue(html.indexOf("\"" + location + "\"") > 0);
}
Also used : BarTrace(tech.tablesaw.plotly.traces.BarTrace) Page(tech.tablesaw.plotly.components.Page) Figure(tech.tablesaw.plotly.components.Figure) Test(org.junit.jupiter.api.Test)

Example 3 with BarTrace

use of tech.tablesaw.plotly.traces.BarTrace in project tablesaw by jtablesaw.

the class BarPieAndParetoExample method main.

public static void main(String[] args) throws Exception {
    // ***************** Setup *************************
    // load the data into a table
    Table tornadoes = Table.read().csv("../data/tornadoes_1950-2014.csv");
    // Get the scale column and replace any values of -9 with the column's missing value indicator
    IntColumn scale = tornadoes.intColumn("scale");
    scale.set(scale.isEqualTo(-9), IntColumnType.missingValueIndicator());
    // ***************** Plotting **********************
    // BAR PLOTS
    // Sum the number of fatalities from each tornado, grouping by scale
    Table fatalities1 = tornadoes.summarize("fatalities", sum).by("scale");
    // Plot
    Plot.show(HorizontalBarPlot.create(// plot title
    "fatalities by scale", // table
    fatalities1, // grouping column name
    "scale", // numeric column name
    "sum [fatalities]"));
    // Plot the mean injuries rather than a sum.
    Table injuries1 = tornadoes.summarize("injuries", mean).by("scale");
    Plot.show(HorizontalBarPlot.create("Average number of tornado injuries by scale", injuries1, "scale", "mean [injuries]"));
    // PIE PLOT
    Plot.show(PiePlot.create("fatalities by scale", fatalities1, "scale", "sum [fatalities]"));
    // PARETO PLOT
    Table t2 = tornadoes.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) IntColumn(tech.tablesaw.api.IntColumn) Figure(tech.tablesaw.plotly.components.Figure)

Example 4 with BarTrace

use of tech.tablesaw.plotly.traces.BarTrace in project tablesaw by jtablesaw.

the class BarTest method show.

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

Example 5 with BarTrace

use of tech.tablesaw.plotly.traces.BarTrace in project tablesaw by jtablesaw.

the class BarTest method testAsJavascript.

@Test
public void testAsJavascript() {
    BarTrace trace = BarTrace.builder(x, y).build();
    System.out.println(trace.asJavascript(1));
}
Also used : BarTrace(tech.tablesaw.plotly.traces.BarTrace) Test(org.junit.jupiter.api.Test)

Aggregations

BarTrace (tech.tablesaw.plotly.traces.BarTrace)10 Figure (tech.tablesaw.plotly.components.Figure)9 Layout (tech.tablesaw.plotly.components.Layout)6 Test (org.junit.jupiter.api.Test)4 Table (tech.tablesaw.api.Table)4 IntColumn (tech.tablesaw.api.IntColumn)2 Page (tech.tablesaw.plotly.components.Page)2 Trace (tech.tablesaw.plotly.traces.Trace)2