Skip to the content.

Contents

Introduction to Plotting with Tablesaw

From the beginning, Tablesaw supported plots for quick, basic, exploratory data analysis. It served its purpose, but fell far short of what the best visualization tools provide. Unfortunately, none of those tools are written in Java.

With version 0.2.0 we introduced a new plotting framework, which provides a Java wrapper around the Plot.ly open source JavaScript visualization library. Plot.ly is based on the extraordinary D3 (Data-Driven Documents) framework, and is certainly among the best open-source visualization packages available in any language. Plot.ly is so good, it has become widely used in languages other than JavaScript such as Python and R, which already had solid options for visualization.

We’ve taken a similar approach to these other languages, providing a wrapper that makes it easy to construct plots in pure Java, And while you can create plots from standard Java objects and primitives, we’ve also ensured that you can build them directly from Tablesaw tables and columns.

This is a huge step forward for Tablesaw in many ways as high quality visualization tools are essential in analytical effort. These are some of the most important benefits:

Please be aware that we don’t support the entire plot.ly API. We do, however, support a large and growing portion.

How it works

There are two ways to work with plotting. You can use the predefined “canned” plots in the api package, or you can roll-your-own custom visualizations.

Pre-defined (“Canned”) plots

The api package contains simplified interfaces for producing a number of common plot types. The goal for these plots is that they can be created and displayed in one or two lines of code. Here’s an example bubble plot:

bubbleplot

And here’s the code to create and display it. In the simple API, rendering a bubble plot requires two steps. First, a call to BubblePlot.create() returns a Figure object, and then the figure is rendered by passing it to a Plot.show() method.

Finding Example Code

You can find example code for all kinds of plots in the test folder of the jsplot project. The code for this specific plot is in the class BubbleExample2:

https://github.com/tlabs-data/tablesaw/tree/master/jsplot/src/test/java/tech/tablesaw/examples/BubbleExample2.java

This writes a generated HTML page containing the necessary JavaScript to a file on the local filesystem, and opens it in a browser window.

Custom visualizations

Custom visualizations are assembled using “figures”, “traces”, and “layouts”. Custom visualizations are described here.

Ways of working

Visualizing data while working in your IDE

When you’re doing data analysis, it’s important to be able to create plots easily in your IDE, so we provide a way to render plots without a servlet engine or web server. To do that, we write an output HTML file to disk and use the default browser on the desktop to load it . The effect is similar to testing Web apps from within an IDE. This is what the call to Plot.show() in the example does

Rendering output to a Web page

You can render plots to web pages easily by getting the JavaScript from figure you want to display. All figures, traces, and layouts implement asJavaScript() which returns a String.

Rendering output in a Java UI

Unfortunately, this isn’t as easy to do as it should be. The JavaFx WebView component is ok for very simple pages, but is too fragile handling JavaScript and CSS-heavy pages for us to support. There are a few other browser components available commercially or as open source if you need to use Tablesaw’s visualization tools, but you may be better off with JavaFx Charts or another pure Java library.

For more information

See Tablesaw and the Tablesaw User Guide for more information.