C3 AI Documentation Home

Plotting in the C3 AI Console

The popular and powerful charting capabilities of the Python matplotlib library, made available through a set of types for other languages, are especially useful for quickly visualizing data structures during exploration and debugging.

While the concepts are borrowed from the Python library, the model has been made more consistent with C3 AI Suite naming conventions and compatible with its processing flow. The major differences from Python are:

  • naming conventions: fill_betweenx becomes fillBetweenX
  • side-effect free: there is no global state, all plotting functions are builders
  • each plot function has a corresponding spec: PlotPieSpec for matplotlib.pyplot.pie

The hierarchy of objects is:

  • figure: top-level object that can be rendered as an image.
  • axes: one or more per figure, each of which is a separate chart.
  • element: one or more plot per axes, each of which is defined by one of the spec types.

The simplest chart is one figure with one axes and a single element. The examples below are for just that, a figure with a single axes and a single line element (Python plot function, C3 PlotPlotSpec).

Here is the Python example:

Python
import random
import matplotlib.pyplot as plt
values = random.sample(xrange(100), 10)
fig, ax = plt.subplots()
ax.plot(values)
ax.set_title('Critical Issues')
plt.show()

Here is the verbose method of building the corresponding figure object and showing it:

JavaScript
var values = C3.Array.patternOfDbl(10, function(n) { return Math.random() * 100; });
PlotFigure.make({
  axes: [ {
    title: 'Critical Issues',
    elements: [ {
      type: 'PlotPlotSpec',
      y: values
    } ]
  } ]
}).show();

See PlotFigure for details.

Here is a more compact way of building the figure object using helper methods:

JavaScript
var values = C3.Array.patternOfDbl(10, function(n) { return Math.random() * 100; });
PlotAxes.make({ title: 'Critical Issues' })
        .plot({ y: values })
        .show();

See PlotAxes for details.

Plot Elements

Was this page helpful?