tech.tablesaw.plotly.components.Layout Java Examples
The following examples show how to use
tech.tablesaw.plotly.components.Layout.
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: ScatterLegendExample.java From tablesaw with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { Table tornadoes = Table.read().csv("../data/tornadoes_1950-2014.csv"); tornadoes = tornadoes.where(tornadoes.nCol("Start lat").isGreaterThan(20)); NumericColumn<?> x = tornadoes.nCol("Start lon"); NumericColumn<?> y = tornadoes.nCol("Start lat"); // show a legend even though there's only one trace, by setting showLegend explicitly to true Layout layout = Layout.builder() .title("tornado start points") .height(600) .width(800) .showLegend(true) .build(); Trace trace = ScatterTrace.builder(x, y).marker(Marker.builder().size(1).build()).name("lat/lon").build(); Plot.show(new Figure(layout, trace)); }
Example #2
Source File: LinePlotExampleWithSmoothing.java From tablesaw with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { Table robberies = Table.read().csv("../data/boston-robberies.csv"); NumericColumn<?> x = robberies.nCol("Record"); NumericColumn<?> y = robberies.nCol("Robberies"); Layout layout = Layout.builder().title("Monthly Boston Armed Robberies Jan. 1966 - Oct. 1975").build(); ScatterTrace trace = ScatterTrace.builder(x, y) .mode(ScatterTrace.Mode.LINE) .line(Line.builder().shape(Line.Shape.SPLINE).smoothing(1.2).build()) .build(); Plot.show(new Figure(layout, trace)); }
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: TimeSeriesPlot.java From tablesaw with Apache License 2.0 | 6 votes |
public static Figure create( String title, Table table, String dateColX, String yCol, String groupCol) { TableSliceGroup tables = table.splitOn(table.categoricalColumn(groupCol)); Layout layout = Layout.builder(title, dateColX, yCol).build(); ScatterTrace[] traces = new ScatterTrace[tables.size()]; for (int i = 0; i < tables.size(); i++) { List<Table> tableList = tables.asTableList(); Table t = tableList.get(i).sortOn(dateColX); traces[i] = ScatterTrace.builder(t.dateColumn(dateColX), t.numberColumn(yCol)) .showLegend(true) .name(tableList.get(i).name()) .mode(ScatterTrace.Mode.LINE) .build(); } return new Figure(layout, traces); }
Example #5
Source File: CandlestickPlot.java From tablesaw with Apache License 2.0 | 6 votes |
public static Figure create( String title, Table table, String xCol, String openCol, String highCol, String lowCol, String closeCol) { Layout layout = Layout.builder(title, xCol).build(); ScatterTrace trace = ScatterTrace.builder( table.dateColumn(xCol), table.numberColumn(openCol), table.numberColumn(highCol), table.numberColumn(lowCol), table.numberColumn(closeCol)) .type("candlestick") .build(); return new Figure(layout, trace); }
Example #6
Source File: ScatterTest.java From tablesaw with Apache License 2.0 | 6 votes |
@Test public void showLine() { Layout layout = Layout.builder() .title("test") .titleFont(Font.builder().size(32).color("green").build()) .showLegend(true) .height(700) .width(1200) .build(); ScatterTrace trace = ScatterTrace.builder(x, y) .mode(ScatterTrace.Mode.LINE) .hoverLabel( HoverLabel.builder().bgColor("red").font(Font.builder().size(24).build()).build()) .showLegend(true) .build(); Figure figure = new Figure(layout, trace); File outputFile = Paths.get("testoutput/output.html").toFile(); Plot.show(figure, "target", outputFile); }
Example #7
Source File: AreaPlot.java From tablesaw with Apache License 2.0 | 6 votes |
public static Figure create( String title, Table table, String xCol, String yCol, String groupCol) { TableSliceGroup tables = table.splitOn(table.categoricalColumn(groupCol)); Layout layout = Layout.builder(title, xCol, yCol).showLegend(true).build(); ScatterTrace[] traces = new ScatterTrace[tables.size()]; for (int i = 0; i < tables.size(); i++) { List<Table> tableList = tables.asTableList(); traces[i] = ScatterTrace.builder( tableList.get(i).numberColumn(xCol), tableList.get(i).numberColumn(yCol)) .showLegend(true) .name(tableList.get(i).name()) .mode(ScatterTrace.Mode.LINE) .fill(ScatterTrace.Fill.TO_NEXT_Y) .build(); } return new Figure(layout, traces); }
Example #8
Source File: OHLCPlot.java From tablesaw with Apache License 2.0 | 6 votes |
public static Figure create( String title, Table table, String xCol, String openCol, String highCol, String lowCol, String closeCol) { Layout layout = Layout.builder(title, xCol).build(); ScatterTrace trace = ScatterTrace.builder( table.dateColumn(xCol), table.numberColumn(openCol), table.numberColumn(highCol), table.numberColumn(lowCol), table.numberColumn(closeCol)) .type("ohlc") .build(); return new Figure(layout, trace); }
Example #9
Source File: Scatter3DPlot.java From tablesaw with Apache License 2.0 | 6 votes |
public static Figure create( String title, Table table, String xCol, String yCol, String zCol, String groupCol) { TableSliceGroup tables = table.splitOn(table.categoricalColumn(groupCol)); Layout layout = standardLayout(title, xCol, yCol, zCol, true); Scatter3DTrace[] traces = new Scatter3DTrace[tables.size()]; for (int i = 0; i < tables.size(); i++) { List<Table> tableList = tables.asTableList(); traces[i] = Scatter3DTrace.builder( tableList.get(i).numberColumn(xCol), tableList.get(i).numberColumn(yCol), tableList.get(i).numberColumn(zCol)) .showLegend(true) .name(tableList.get(i).name()) .build(); } return new Figure(layout, traces); }
Example #10
Source File: ScatterPlot.java From tablesaw with Apache License 2.0 | 6 votes |
public static Figure create( String title, Table table, String xCol, String yCol, String groupCol) { TableSliceGroup tables = table.splitOn(table.categoricalColumn(groupCol)); Layout layout = Layout.builder(title, xCol, yCol).showLegend(true).build(); ScatterTrace[] traces = new ScatterTrace[tables.size()]; Marker marker = Marker.builder().opacity(OPACITY).build(); for (int i = 0; i < tables.size(); i++) { List<Table> tableList = tables.asTableList(); traces[i] = ScatterTrace.builder( tableList.get(i).numberColumn(xCol), tableList.get(i).numberColumn(yCol)) .showLegend(true) .marker(marker) .name(tableList.get(i).name()) .build(); } return new Figure(layout, traces); }
Example #11
Source File: LinePlot.java From tablesaw with Apache License 2.0 | 6 votes |
public static Figure create( String title, Table table, String xCol, String yCol, String groupCol) { TableSliceGroup tables = table.splitOn(table.categoricalColumn(groupCol)); Layout layout = Layout.builder(title, xCol, yCol).showLegend(true).build(); ScatterTrace[] traces = new ScatterTrace[tables.size()]; for (int i = 0; i < tables.size(); i++) { List<Table> tableList = tables.asTableList(); traces[i] = ScatterTrace.builder( tableList.get(i).numberColumn(xCol), tableList.get(i).numberColumn(yCol)) .showLegend(true) .name(tableList.get(i).name()) .mode(ScatterTrace.Mode.LINE) .build(); } return new Figure(layout, traces); }
Example #12
Source File: QuantilePlot.java From tablesaw with Apache License 2.0 | 6 votes |
/** * Returns a figure containing a Quantile Plot describing the distribution of values in the column * of interest * * @param title A title for the plot * @param table The table containing the column of interest * @param columnName The name of the numeric column containing the data to plot * @return A quantile plot */ public static Figure create(String title, Table table, String columnName) { NumericColumn<?> xCol = table.nCol(columnName); double[] x = new double[xCol.size()]; for (int i = 0; i < x.length; i++) { x[i] = i / (float) x.length; } NumericColumn<?> copy = xCol.copy(); copy.sortAscending(); ScatterTrace trace = ScatterTrace.builder(x, copy.asDoubleArray()).build(); Layout layout = Layout.builder().title(title).build(); return new Figure(layout, trace); }
Example #13
Source File: BubblePlot.java From tablesaw with Apache License 2.0 | 6 votes |
public static Figure create( String title, Table table, String xCol, String yCol, String sizeColumn, String groupCol) { TableSliceGroup tables = table.splitOn(table.categoricalColumn(groupCol)); Layout layout = Layout.builder(title, xCol, yCol).showLegend(true).build(); ScatterTrace[] traces = new ScatterTrace[tables.size()]; for (int i = 0; i < tables.size(); i++) { List<Table> tableList = tables.asTableList(); Marker marker = Marker.builder() .size(tableList.get(i).numberColumn(sizeColumn)) // .opacity(.75) .build(); traces[i] = ScatterTrace.builder( tableList.get(i).numberColumn(xCol), tableList.get(i).numberColumn(yCol)) .showLegend(true) .marker(marker) .name(tableList.get(i).name()) .build(); } return new Figure(layout, traces); }
Example #14
Source File: MarkerOptionsExample.java From tablesaw with Apache License 2.0 | 6 votes |
/** Shows a scatter with an outline on the marker */ private void showCustomLine() { Layout layout = Layout.builder() .title("outline") .xAxis(Axis.builder().title("Batting Average").build()) .yAxis(Axis.builder().title("Wins").build()) .build(); Trace trace = ScatterTrace.builder(x, y) .marker( Marker.builder() .line(Line.builder().color("rgb(231, 99, 250)").width(1).build()) .build()) .build(); Plot.show(new Figure(layout, trace)); }
Example #15
Source File: LayoutTest.java From tablesaw with Apache License 2.0 | 6 votes |
public void asJavascriptForGrid() { Axis x = Axis.builder().title("x axis").build(); Axis y = Axis.builder().title("y axis").build(); Grid grid = Grid.builder().rows(2).columns(2).build(); Layout layout = Layout.builder() .title("foobar") .xAxis(x) .yAxis(y) .grid(grid) .showLegend(true) .margin(Margin.builder().top(100).bottom(100).left(200).right(200).build()) .build(); String asJavascript = layout.asJavascript(); assertTrue(asJavascript.contains("rows")); assertTrue(asJavascript.contains("columns")); assertTrue(asJavascript.contains("rows")); assertTrue(asJavascript.contains("xAxis")); }
Example #16
Source File: MarkerOptionsExample.java From tablesaw with Apache License 2.0 | 6 votes |
/** * Shows a scatter with a gradient. In this example we set both the type and the color (which is * used as the value to shade into). Color normally defaults to a dark neutral grey (black?) * * <p>The size is increased to make the gradient more visible */ private void showMarkerGradient() { Layout layout = Layout.builder() .title("marker gradient") .xAxis(Axis.builder().title("Batting Average").build()) .yAxis(Axis.builder().title("Wins").build()) .build(); Trace trace = ScatterTrace.builder(x, y) .marker( Marker.builder() .size(10) .gradient( Gradient.builder().type(Gradient.Type.HORIZONTAL).color("red").build()) .build()) .build(); Plot.show(new Figure(layout, trace)); }
Example #17
Source File: MarkerOptionsExample.java From tablesaw with Apache License 2.0 | 6 votes |
/** * Shows a scatter with color set as a color scale * * <p>The color scale requires that an array of numeric values be provided, here we just scale * according to the number of wins the team has. */ private void showColorScaleWithBar() { Layout layout = Layout.builder() .title("color scaled with color bar") .xAxis(Axis.builder().title("Batting Average").build()) .yAxis(Axis.builder().title("Wins").build()) .build(); IntColumn wins = baseball.intColumn("W"); Trace trace = ScatterTrace.builder(x, y) .marker( Marker.builder() .color(wins.asDoubleArray()) .cMinAndMax(wins.min(), wins.max()) .colorScale(Marker.Palette.YL_GN_BU) .showScale(true) .build()) .build(); Plot.show(new Figure(layout, trace)); }
Example #18
Source File: MarkerOptionsExample.java From tablesaw with Apache License 2.0 | 6 votes |
/** * Shows a scatter with color set as a color scale * * <p>The color scale requires that an array of numeric values be provided, here we just scale * according to the number of wins the team has. */ private void showColorScale() { Layout layout = Layout.builder() .title("color scaled by # of wins") .xAxis(Axis.builder().title("Batting Average").build()) .yAxis(Axis.builder().title("Wins").build()) .build(); IntColumn wins = baseball.intColumn("W"); Trace trace = ScatterTrace.builder(x, y) .marker( Marker.builder() .color(wins.asDoubleArray()) .cMinAndMax(wins.min(), wins.max()) .colorScale(Marker.Palette.YL_GN_BU) .build()) .build(); Plot.show(new Figure(layout, trace)); }
Example #19
Source File: HistogramFuncExample.java From tablesaw with Apache License 2.0 | 6 votes |
public static void main(String[] args) { Table test = Table.create( StringColumn.create("type").append("apples").append("apples").append("apples").append("oranges").append("bananas"), IntColumn.create("num").append(5).append(10).append(3).append(10).append(5)); Layout layout1 = Layout.builder().title("Histogram COUNT Test (team batting averages)").build(); HistogramTrace trace = HistogramTrace. builder(test.stringColumn("type"), test.intColumn("num")) .histFunc(COUNT) .build(); Plot.show(new Figure(layout1, trace)); Layout layout2 = Layout.builder().title("Hist SUM Test (team batting averages)").build(); HistogramTrace trace2 = HistogramTrace. builder(test.stringColumn("type"), test.intColumn("num")) .histFunc(SUM) .build(); Plot.show(new Figure(layout2, trace2)); }
Example #20
Source File: DistributionVisualizations.java From tablesaw with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { Table property = Table.read().csv("../data/sacramento_real_estate_transactions.csv"); IntColumn sqft = property.intColumn("sq__ft"); IntColumn price = property.intColumn("price"); sqft.set(sqft.isEqualTo(0), IntColumnType.missingValueIndicator()); price.set(price.isEqualTo(0), IntColumnType.missingValueIndicator()); Plot.show(Histogram.create("Distribution of prices", property.numberColumn("price"))); Layout layout = Layout.builder().title("Distribution of property sizes").build(); HistogramTrace trace = HistogramTrace.builder(property.numberColumn("sq__ft")) .marker(Marker.builder().color("#B10DC9").opacity(.70).build()) .build(); Plot.show(new Figure(layout, trace)); Plot.show(Histogram2D.create("Distribution of price and size", property, "price", "sq__ft")); Plot.show(BoxPlot.create("Prices by property type", property, "type", "price")); }
Example #21
Source File: BoxExample.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"); Layout layout = Layout.builder().title("Tornado Injuries by Scale").build(); BoxTrace trace = BoxTrace.builder(table.categoricalColumn("scale"), table.nCol("injuries")).build(); Plot.show(new Figure(layout, trace)); }
Example #22
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 #23
Source File: MarkerOptionsExample.java From tablesaw with Apache License 2.0 | 5 votes |
/** Shows a scatter with red markers */ private void showRedMarkers() { Layout layout = Layout.builder() .title("red markers") .xAxis(Axis.builder().title("Batting Average").build()) .yAxis(Axis.builder().title("Wins").build()) .build(); Trace trace = ScatterTrace.builder(x, y).marker(Marker.builder().color("red").build()).build(); Plot.show(new Figure(layout, trace)); }
Example #24
Source File: AreaPlot.java From tablesaw with Apache License 2.0 | 5 votes |
public static Figure create(String title, Table table, String xCol, String yCol) { Layout layout = Layout.builder(title, xCol, yCol).build(); ScatterTrace trace = ScatterTrace.builder(table.numberColumn(xCol), table.numberColumn(yCol)) .mode(ScatterTrace.Mode.LINE) .fill(ScatterTrace.Fill.TO_NEXT_Y) .build(); return new Figure(layout, trace); }
Example #25
Source File: HistogramTraceTest.java From tablesaw with Apache License 2.0 | 5 votes |
@Test public void show() { Layout layout = Layout.builder().barMode(Layout.BarMode.OVERLAY).build(); HistogramTrace trace1 = HistogramTrace.builder(y1).opacity(.75).build(); HistogramTrace trace2 = HistogramTrace.builder(y2).opacity(.75).build(); Plot.show(new Figure(layout, trace1, trace2)); }
Example #26
Source File: MarkerOptionsExample.java From tablesaw with Apache License 2.0 | 5 votes |
/** * Shows a scatter with a bowtie symbol instead of a circle. Many other options are available as * defined by the Symbol enum */ private void showBowTieSymbol() { Layout layout = Layout.builder() .title("custom symbol type: Bow Tie") .xAxis(Axis.builder().title("Batting Average").build()) .yAxis(Axis.builder().title("Wins").build()) .build(); Trace trace = ScatterTrace.builder(x, y).marker(Marker.builder().symbol(Symbol.BOWTIE).build()).build(); Plot.show(new Figure(layout, trace)); }
Example #27
Source File: HistogramOverlayExample.java From tablesaw with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { Table baseball = Table.read().csv("../data/baseball.csv"); Layout layout = Layout.builder() .title("Distribution of team batting averages") .barMode(Layout.BarMode.OVERLAY) .showLegend(true) .build(); TableSliceGroup groups = baseball.splitOn("league"); Table t1 = groups.get(0).asTable(); HistogramTrace trace1 = HistogramTrace.builder(t1.nCol("BA")) .name("American Leage") .opacity(.75) .nBinsX(24) .marker(Marker.builder().color("#FF4136").build()) .build(); Table t2 = groups.get(1).asTable(); HistogramTrace trace2 = HistogramTrace.builder(t2.nCol("BA")) .name("National League") .opacity(.75) .nBinsX(24) .marker(Marker.builder().color("#7FDBFF").build()) .build(); Plot.show(new Figure(layout, trace1, trace2)); }
Example #28
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 #29
Source File: LinePlotExample.java From tablesaw with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { Table robberies = Table.read().csv("../data/boston-robberies.csv"); NumericColumn<?> x = robberies.nCol("Record"); NumericColumn<?> y = robberies.nCol("Robberies"); Layout layout = Layout.builder().title("Monthly Boston Armed Robberies Jan. 1966 - Oct. 1975").build(); ScatterTrace trace = ScatterTrace.builder(x, y).mode(ScatterTrace.Mode.LINE).build(); Plot.show(new Figure(layout, trace)); }
Example #30
Source File: MarkerOptionsExample.java From tablesaw with Apache License 2.0 | 5 votes |
/** Shows a scatter with 50% opacity */ private void show50PctOpacity() { Layout layout = Layout.builder() .title("50% opacity") .xAxis(Axis.builder().title("Batting Average").build()) .yAxis(Axis.builder().title("Wins").build()) .build(); Trace trace = ScatterTrace.builder(x, y).marker(Marker.builder().opacity(.5).build()).build(); Plot.show(new Figure(layout, trace)); }