tech.tablesaw.plotly.components.Figure Java Examples
The following examples show how to use
tech.tablesaw.plotly.components.Figure.
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: 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 #3
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 #4
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 #5
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 #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: 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 #8
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 #9
Source File: ScatterplotWithSpecificAxisRange.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"); Layout layout = Layout.builder() .title("tornado start points") .height(600) .width(800) .yAxis(Axis.builder().range(20, 60).build()) .build(); Trace trace = ScatterTrace.builder(x, y).marker(Marker.builder().size(1).build()).name("lat/lon").build(); Plot.show(new Figure(layout, trace)); }
Example #10
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 #11
Source File: BubbleExample2.java From tablesaw with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws IOException { Table wines = Table.read().csv("../data/test_wines.csv"); Table champagne = wines.where( wines .stringColumn("wine type") .isEqualTo("Champagne & Sparkling") .and(wines.stringColumn("region").isEqualTo("California"))); Figure figure = BubblePlot.create( "Average retail price for champagnes by year and rating", champagne, // table name "highest pro score", // x variable column name "year", // y variable column name "Mean Retail" // bubble size ); Plot.show(figure); }
Example #12
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 #13
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 #14
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 #15
Source File: BubbleTest.java From tablesaw with Apache License 2.0 | 6 votes |
@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)); }
Example #16
Source File: ScatterplotWithTwoYAxes.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"); NumericColumn<?> x = baseball.nCol("BA"); NumericColumn<?> y = baseball.nCol("W"); NumericColumn<?> y2 = baseball.nCol("SLG"); Layout layout = Layout.builder() .title("Wins vs BA and SLG") .xAxis(Axis.builder().title("Batting Average").build()) .yAxis(Axis.builder().title("Wins").build()) .yAxis2( Axis.builder() .title("SLG") .side(Axis.Side.right) .overlaying(ScatterTrace.YAxis.Y) .build()) .build(); Trace trace = ScatterTrace.builder(x, y) .name("Batting avg.") .marker(Marker.builder().opacity(.7).color("#01FF70").build()) .build(); Trace trace2 = ScatterTrace.builder(x, y2) .yAxis(ScatterTrace.YAxis.Y2) .name("Slugging pct.") .marker(Marker.builder().opacity(.7).color("rgb(17, 157, 255)").build()) .build(); Figure figure = new Figure(layout, trace2, trace); Plot.show(figure); }
Example #17
Source File: BoxTest.java From tablesaw with Apache License 2.0 | 5 votes |
@Test void show() { BoxTrace trace = BoxTrace.builder(x, y).build(); Figure figure = new Figure(trace); assertNotNull(figure); Plot.show(figure, "target"); }
Example #18
Source File: MarkerOptionsExample.java From tablesaw with Apache License 2.0 | 5 votes |
/** Shows a scatter with no marker customization */ private void showDefault() { Layout layout = Layout.builder() .title("default") .xAxis(Axis.builder().title("Batting Average").build()) .yAxis(Axis.builder().title("Wins").build()) .build(); Trace trace = ScatterTrace.builder(x, y).build(); Plot.show(new Figure(layout, trace)); }
Example #19
Source File: HeatmapExample.java From tablesaw with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { Table table = Table.read().csv("../data/bush.csv"); StringColumn yearsMonth = table.dateColumn("date").yearMonth(); String name = "Year and month"; yearsMonth.setName(name); table.addColumns(yearsMonth); Figure heatmap = Heatmap.create("Polls conducted by year and month", table, name, "who"); Plot.show(heatmap); }
Example #20
Source File: MultiPlotExample.java From tablesaw with Apache License 2.0 | 5 votes |
private static String makePage(Figure figure1, Figure figure2, String divName1, String divName2) { return new StringBuilder() .append(pageTop) .append(System.lineSeparator()) .append(figure1.asJavascript(divName1)) .append(System.lineSeparator()) .append(figure2.asJavascript(divName2)) .append(System.lineSeparator()) .append(pageBottom) .toString(); }
Example #21
Source File: HistogramHorizontalExample.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(); Table t2 = groups.get(1).asTable(); HistogramTrace trace1 = HistogramTrace.builder(t1.nCol("BA")) .name("American League") .opacity(.75) .nBinsY(24) .horizontal(true) .marker(Marker.builder().color("#FF4136").build()) .build(); HistogramTrace trace2 = HistogramTrace.builder(t2.nCol("BA")) .name("National League") .opacity(.75) .nBinsY(24) .horizontal(true) .marker(Marker.builder().color("#7FDBFF").build()) .build(); Plot.show(new Figure(layout, trace1, trace2)); }
Example #22
Source File: LineOptionsExample.java From tablesaw with Apache License 2.0 | 5 votes |
/** Sets the line width */ private void showWideLines() { Layout layout = Layout.builder().title("Wide lines").build(); ScatterTrace trace = ScatterTrace.builder(x, y) .mode(ScatterTrace.Mode.LINE) .line(Line.builder().width(4).build()) .build(); Plot.show(new Figure(layout, trace)); }
Example #23
Source File: Heatmap.java From tablesaw with Apache License 2.0 | 5 votes |
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); }
Example #24
Source File: HistogramProbabilityExample.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("Probability Histogram of team batting averages").build(); HistogramTrace trace = HistogramTrace. builder(baseball.nCol("BA")) .histNorm(HistogramTrace.HistNorm.PROBABILITY) .build(); Plot.show(new Figure(layout, trace)); }
Example #25
Source File: HistogramExample.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").build(); HistogramTrace trace = HistogramTrace.builder(baseball.nCol("BA")).build(); Plot.show(new Figure(layout, trace)); }
Example #26
Source File: ScattterPlotMatrixExample.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").sampleN(500); List<NumericColumn<?>> columns = table.numericColumns().subList(0, 6); List<Trace> traceList = new ArrayList<>(); int count = 1; for (int i = 0; i < columns.size(); i++) { for (NumericColumn<?> column : columns) { Trace t = ScatterTrace.builder(column.asDoubleArray(), columns.get(i).asDoubleArray()) .xAxis("x" + count) .yAxis("y" + count) .name(columns.get(i).name() + " x " + column.name()) .marker(Marker.builder().size(3).opacity(.5).build()) .build(); traceList.add(t); count++; } } Trace[] traces = traceList.toArray(new Trace[0]); Grid grid = Grid.builder() .columns(columns.size()) .rows(columns.size()) .pattern(Grid.Pattern.INDEPENDENT) .xSide(Grid.XSide.BOTTOM) .build(); Layout layout = Layout.builder().title("Scatter Plot Matrix").width(1100).height(1100).grid(grid).build(); Plot.show(new Figure(layout, traces)); }
Example #27
Source File: PieTest.java From tablesaw with Apache License 2.0 | 5 votes |
@Test public void show() { PieTrace trace = PieTrace.builder(x, y).build(); Figure figure = new Figure(trace); File outputFile = Paths.get("testoutput/output.html").toFile(); Plot.show(figure, "target", outputFile); }
Example #28
Source File: LinePlot.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) .build(); return new Figure(layout, trace); }
Example #29
Source File: Plot.java From tablesaw with Apache License 2.0 | 5 votes |
public static void show(Figure figure, String divName, File outputFile) { Page page = Page.pageBuilder(figure, divName).build(); String output = page.asJavascript(); try { try (Writer writer = new OutputStreamWriter(new FileOutputStream(outputFile), StandardCharsets.UTF_8)) { writer.write(output); } new Browser().browse(outputFile); } catch (IOException e) { throw new UncheckedIOException(e); } }
Example #30
Source File: PieExample.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 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)); }