use of tech.tablesaw.plotly.components.Figure in project tablesaw by jtablesaw.
the class MultiPlotExample method main.
public static void main(String[] args) throws Exception {
/*
Preliminaries:
1. Get a table
2. Split the data into two tables, one for each league
3. Get the columns we're going to use in the plot as x1, y1, x2, y2
4. Create a layout for each plot
5. Create the traces for each plot
6. Build a Figure for each plot from the layout and trace
7. Create an HTML page as a string
8. Write the string to a file
9. Open the default desktop Web browser on the file so you can see it
*/
// 1. Get a table
Table baseball = Table.read().csv("../data/baseball.csv");
// 2. Split the data into two tables, one for each league
List<Table> leagueTables = baseball.splitOn("league").asTableList();
Table league1 = leagueTables.get(0);
Table league2 = leagueTables.get(1);
// 3. Get the columns we're going to use in the plot as x1, y1, x2, y2
NumericColumn<?> x1 = league1.nCol("BA");
NumericColumn<?> y1 = league1.nCol("W");
NumericColumn<?> x2 = league2.nCol("BA");
NumericColumn<?> y2 = league2.nCol("W");
// 4. Create a layout for each plot
Layout layout1 = Layout.builder().title("American League Wins vs BA").xAxis(Axis.builder().title("Batting Average").build()).yAxis(Axis.builder().title("Wins").build()).build();
Layout layout2 = Layout.builder().title("National League Wins vs BA").xAxis(Axis.builder().title("Batting Average").build()).yAxis(Axis.builder().title("Wins").build()).build();
// 5. Create the traces for each plot
Trace trace1 = ScatterTrace.builder(x1, y1).build();
Trace trace2 = ScatterTrace.builder(x2, y2).build();
// 6. Build a Figure for each plot from the layout and trace
Figure figure1 = new Figure(layout1, trace1);
Figure figure2 = new Figure(layout2, trace2);
// 7. Create an HTML page as a string
String divName1 = "plot1";
String divName2 = "plot2";
String page = makePage(figure1, figure2, divName1, divName2);
// 8. Write the string to a file
// uncomment to try (see imports also)
/*
File outputFile = Paths.get("multiplot.html").toFile();
try {
try (FileWriter fileWriter = new FileWriter(outputFile)) {
fileWriter.write(page);
}
} catch (IOException e) {
e.printStackTrace();
}
*/
// 9. Open the default desktop Web browser on the file so you can see it
// uncomment to try
// new Browser().browse(outputFile);
}
use of tech.tablesaw.plotly.components.Figure 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));
}
use of tech.tablesaw.plotly.components.Figure in project tablesaw by jtablesaw.
the class PieExample method main.
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));
}
use of tech.tablesaw.plotly.components.Figure in project tablesaw by jtablesaw.
the class BubbleTest method showScatter.
@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));
}
use of tech.tablesaw.plotly.components.Figure in project tablesaw by jtablesaw.
the class ContourTest method testContourTrace.
@Test
public void testContourTrace() {
ContourTrace trace = ContourTrace.builder(x, y, z).build();
Figure figure = new Figure(trace);
Plot.show(figure);
}
Aggregations