tech.tablesaw.plotly.traces.BarTrace Java Examples
The following examples show how to use
tech.tablesaw.plotly.traces.BarTrace.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BarPlot.java From tablesaw with Apache License 2.0 | 6 votes |
protected static Figure create( Orientation orientation, String title, Table table, String groupColName, Layout.BarMode barMode, String... numberColNames) { Layout layout = standardLayout(title).barMode(barMode).showLegend(true).build(); Trace[] traces = new Trace[numberColNames.length]; for (int i = 0; i < numberColNames.length; i++) { String name = numberColNames[i]; BarTrace trace = BarTrace.builder(table.categoricalColumn(groupColName), table.numberColumn(name)) .orientation(orientation) .showLegend(true) .name(name) .build(); traces[i] = trace; } return new Figure(layout, traces); }
Example #2
Source File: Example8.java From quandl4j with Apache License 2.0 | 6 votes |
/** * The main body of the code. */ private void run() { TableSawQuandlSession session = TableSawQuandlSession.create(); Table table = session.getDataSet( DataSetRequest.Builder.of("WIKI/AAPL").build()); // Create a new column containing the year IntColumn yearColumn = table.dateColumn("Date").year(); yearColumn.setName("Year"); table.addColumns(yearColumn); // Create max, min and total volume tables aggregated by year Table summaryMax = table.summarize("Close", max).by("year"); Table summaryMin = table.summarize("Close", min).by("year"); Table summaryVolume = table.summarize("Volume", sum).by("year"); // Create a new table from each of these Table summary = Table.create("Summary", summaryMax.column(0), summaryMax.column(1), summaryMin.column(1), summaryVolume.column(1)); // Show the max close price as a graph. try { Plot.show(new Figure(BarTrace.builder(summary.intColumn("Year"), summary.numberColumn(1)).build())); } catch (Exception e) { e.printStackTrace(); } System.out.println(summary); }
Example #3
Source File: BarPlot.java From tablesaw with Apache License 2.0 | 6 votes |
protected static Figure create( Orientation orientation, String title, Table table, String groupColName, Layout.BarMode barMode, String... numberColNames) { Layout layout = standardLayout(title).barMode(barMode).showLegend(true).build(); Trace[] traces = new Trace[numberColNames.length]; for (int i = 0; i < numberColNames.length; i++) { String name = numberColNames[i]; BarTrace trace = BarTrace.builder(table.categoricalColumn(groupColName), table.numberColumn(name)) .orientation(orientation) .showLegend(true) .name(name) .build(); traces[i] = trace; } return new Figure(layout, traces); }
Example #4
Source File: ParetoExample.java From tablesaw with Apache License 2.0 | 5 votes |
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)); }
Example #5
Source File: BarPlot.java From tablesaw with Apache License 2.0 | 5 votes |
protected static Figure create( Orientation orientation, String title, Table table, String groupColName, String numberColName) { Layout layout = standardLayout(title).build(); BarTrace trace = BarTrace.builder(table.categoricalColumn(groupColName), table.numberColumn(numberColName)) .orientation(orientation) .build(); return new Figure(layout, trace); }
Example #6
Source File: PageTest.java From tablesaw with Apache License 2.0 | 5 votes |
@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); }
Example #7
Source File: PageTest.java From tablesaw with Apache License 2.0 | 5 votes |
@Test public void testDefaultPlotlyJsLocation() { BarTrace trace = BarTrace.builder(x, y).build(); Page page = Page.pageBuilder(new Figure(trace), "plot").build(); String html = page.asJavascript(); assertTrue(html.indexOf("\"" + "https://cdn.plot.ly/plotly-latest.min.js" + "\"") > 0); }
Example #8
Source File: BarTest.java From tablesaw with Apache License 2.0 | 5 votes |
@Test public void show() { BarTrace trace = BarTrace.builder(x, y).build(); Figure figure = new Figure(trace); Plot.show(figure, "target"); }
Example #9
Source File: HorizontalBarExample.java From tablesaw with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { Table table = Table.read().csv("../data/tornadoes_1950-2014.csv"); Table s = table.summarize("fatalities", count).by("State"); BarTrace trace = BarTrace.builder(s.categoricalColumn(0), s.numberColumn(1)) .orientation(BarTrace.Orientation.HORIZONTAL) .build(); Layout layout = Layout.builder().title("Tornadoes by state").height(600).width(800).build(); Plot.show(new Figure(layout, trace)); }
Example #10
Source File: ParetoExample.java From tablesaw with Apache License 2.0 | 5 votes |
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)); }
Example #11
Source File: BarPlot.java From tablesaw with Apache License 2.0 | 5 votes |
protected static Figure create( Orientation orientation, String title, Table table, String groupColName, String numberColName) { Layout layout = standardLayout(title).build(); BarTrace trace = BarTrace.builder(table.categoricalColumn(groupColName), table.numberColumn(numberColName)) .orientation(orientation) .build(); return new Figure(layout, trace); }
Example #12
Source File: PageTest.java From tablesaw with Apache License 2.0 | 5 votes |
@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); }
Example #13
Source File: PageTest.java From tablesaw with Apache License 2.0 | 5 votes |
@Test public void testDefaultPlotlyJsLocation() { BarTrace trace = BarTrace.builder(x, y).build(); Page page = Page.pageBuilder(new Figure(trace), "plot").build(); String html = page.asJavascript(); assertTrue(html.indexOf("\"" + "https://cdn.plot.ly/plotly-latest.min.js" + "\"") > 0); }
Example #14
Source File: BarTest.java From tablesaw with Apache License 2.0 | 5 votes |
@Test public void show() { BarTrace trace = BarTrace.builder(x, y).build(); Figure figure = new Figure(trace); Plot.show(figure, "target"); }
Example #15
Source File: HorizontalBarExample.java From tablesaw with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { Table table = Table.read().csv("../data/tornadoes_1950-2014.csv"); Table s = table.summarize("fatalities", count).by("State"); BarTrace trace = BarTrace.builder(s.categoricalColumn(0), s.numberColumn(1)) .orientation(BarTrace.Orientation.HORIZONTAL) .build(); Layout layout = Layout.builder().title("Tornadoes by state").height(600).width(800).build(); Plot.show(new Figure(layout, trace)); }
Example #16
Source File: BarExample.java From tablesaw with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { Table table = Table.read().csv("../data/tornadoes_1950-2014.csv"); NumericColumn<?> logNInjuries = table.numberColumn("injuries").add(1).logN(); logNInjuries.setName("log injuries"); table.addColumns(logNInjuries); IntColumn scale = table.intColumn("scale"); scale.set(scale.isLessThan(0), IntColumnType.missingValueIndicator()); Table summaryTable = table.summarize("fatalities", "log injuries", sum).by("Scale"); Plot.show( HorizontalBarPlot.create( "Tornado Impact", summaryTable, "scale", Layout.BarMode.STACK, "Sum [Fatalities]", "Sum [log injuries]")); Plot.show( VerticalBarPlot.create( "Tornado Impact", summaryTable, "scale", Layout.BarMode.GROUP, "Sum [Fatalities]", "Sum [log injuries]")); Layout layout = Layout.builder() .title("Tornado Impact") .barMode(Layout.BarMode.GROUP) .showLegend(true) .build(); String[] numberColNames = {"Sum [Fatalities]", "Sum [log injuries]"}; String[] colors = {"#85144b", "#FF4136"}; Trace[] traces = new Trace[2]; for (int i = 0; i < 2; i++) { String name = numberColNames[i]; BarTrace trace = BarTrace.builder(summaryTable.categoricalColumn("scale"), summaryTable.numberColumn(name)) .orientation(BarTrace.Orientation.VERTICAL) .marker(Marker.builder().color(colors[i]).build()) .showLegend(true) .name(name) .build(); traces[i] = trace; } Plot.show(new Figure(layout, traces)); }
Example #17
Source File: BarExample.java From tablesaw with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { Table table = Table.read().csv("../data/tornadoes_1950-2014.csv"); NumericColumn<?> logNInjuries = table.numberColumn("injuries").add(1).logN(); logNInjuries.setName("log injuries"); table.addColumns(logNInjuries); IntColumn scale = table.intColumn("scale"); scale.set(scale.isLessThan(0), IntColumnType.missingValueIndicator()); Table summaryTable = table.summarize("fatalities", "log injuries", sum).by("Scale"); Plot.show( HorizontalBarPlot.create( "Tornado Impact", summaryTable, "scale", Layout.BarMode.STACK, "Sum [Fatalities]", "Sum [log injuries]")); Plot.show( VerticalBarPlot.create( "Tornado Impact", summaryTable, "scale", Layout.BarMode.GROUP, "Sum [Fatalities]", "Sum [log injuries]")); Layout layout = Layout.builder() .title("Tornado Impact") .barMode(Layout.BarMode.GROUP) .showLegend(true) .build(); String[] numberColNames = {"Sum [Fatalities]", "Sum [log injuries]"}; String[] colors = {"#85144b", "#FF4136"}; Trace[] traces = new Trace[2]; for (int i = 0; i < 2; i++) { String name = numberColNames[i]; BarTrace trace = BarTrace.builder(summaryTable.categoricalColumn("scale"), summaryTable.numberColumn(name)) .orientation(BarTrace.Orientation.VERTICAL) .marker(Marker.builder().color(colors[i]).build()) .showLegend(true) .name(name) .build(); traces[i] = trace; } Plot.show(new Figure(layout, traces)); }
Example #18
Source File: BarPieAndParetoExample.java From tablesaw with Apache License 2.0 | 4 votes |
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( "fatalities by scale", // plot title fatalities1, // table "scale", // grouping column name "sum [fatalities]")); // numeric column name // 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)); }
Example #19
Source File: BarTest.java From tablesaw with Apache License 2.0 | 4 votes |
@Test public void testAsJavascript() { BarTrace trace = BarTrace.builder(x, y).build(); System.out.println(trace.asJavascript(1)); }
Example #20
Source File: BarTest.java From tablesaw with Apache License 2.0 | 4 votes |
@Test public void testAsJavascript() { BarTrace trace = BarTrace.builder(x, y).build(); System.out.println(trace.asJavascript(1)); }
Example #21
Source File: BarPieAndParetoExample.java From tablesaw with Apache License 2.0 | 4 votes |
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( "fatalities by scale", // plot title fatalities1, // table "scale", // grouping column name "sum [fatalities]")); // numeric column name // 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)); }