tech.tablesaw.plotly.Plot Java Examples
The following examples show how to use
tech.tablesaw.plotly.Plot.
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: 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 #2
Source File: QQPlotExample.java From tablesaw with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { Table baseball = Table.read().csv("../data/baseball.csv"); Plot.show(QQPlot.create("batting averages and On-base percent", baseball, "BA", "SLG")); // example with different sized arrays; double[] first = new NormalDistribution().sample(100); double[] second = new NormalDistribution().sample(200); Plot.show( QQPlot.create( "Test of different sized arrays", "short array", first, "long array", second)); // example with different sized arrays; first = new NormalDistribution().sample(20000); second = new NormalDistribution().sample(19990); Plot.show( QQPlot.create( "Test of different sized arrays", "long array", first, "short array", second)); }
Example #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #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: 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 #16
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 #17
Source File: QQPlotExample.java From tablesaw with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { Table baseball = Table.read().csv("../data/baseball.csv"); Plot.show(QQPlot.create("batting averages and On-base percent", baseball, "BA", "SLG")); // example with different sized arrays; double[] first = new NormalDistribution().sample(100); double[] second = new NormalDistribution().sample(200); Plot.show( QQPlot.create( "Test of different sized arrays", "short array", first, "long array", second)); // example with different sized arrays; first = new NormalDistribution().sample(20000); second = new NormalDistribution().sample(19990); Plot.show( QQPlot.create( "Test of different sized arrays", "long array", first, "short array", second)); }
Example #18
Source File: TukeyMeanDistributionPlotExample.java From tablesaw with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { Table baseball = Table.read().csv("../data/baseball.csv"); Table nl = baseball.where(baseball.stringColumn("league").isEqualTo("NL")); Table al = baseball.where(baseball.stringColumn("league").isEqualTo("AL")); Plot.show( TukeyMeanDifferencePlot.create( "Wins NL vs AL", "wins", nl.intColumn("W").asDoubleArray(), al.intColumn("W").asDoubleArray())); // example with difference sized arrays; double[] first = new NormalDistribution().sample(100); double[] second = new NormalDistribution().sample(200); Plot.show( TukeyMeanDifferencePlot.create( "Test of different sized arrays", "random data", first, second)); }
Example #19
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 #20
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)); }
Example #21
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)); }
Example #22
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 #23
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 #24
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 #25
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 #26
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 #27
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)); }
Example #28
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 #29
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 #30
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)); }