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_betweenxbecomesfillBetweenX - 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:
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:
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:
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
plotPlotPlotSpec — Plot y versus x as lines and/or markers.errorBarPlotErrorBarSpec — Plot y versus x as lines and/or markers with attached errorbars.scatterPlotScatterSpec — A scatter plot of y vs x with varying marker size and/or color.plotDatePlotPlotDateSpec — Plot data that contains dates.stepPlotStepSpec — Make a step plot.logLogPlotLogLogSpec — Make a plot with log scaling on both the x and y axis.semiLogXPlotSemiLogXSpec — Make a plot with log scaling on the x axis.semiLogYPlotSemiLogYSpec — Make a plot with log scaling on the y axis.fillBetweenPlotFillBetweenSpec — Fill the area between two horizontal curves.fillBetweenXPlotFillBetweenXSpec — Fill the area between two vertical curves.barPlotBarSpec — Make a bar plot.barHPlotBarHSpec — Make a horizontal bar plot.stemPlotStemSpec — Create a stem plot.eventPlotPlotEventPlotSpec — Plot identical parallel lines at the given positions.piePlotPieSpec — Plot a pie chart.stackPlotPlotStackPlotSpec — Draws a stacked area plot.brokenBarHPlotBrokenBarHSpec — Plot a horizontal sequence of rectangles.vLinesPlotVLinesSpec — Plot vertical lines.hLinesPlotHLinesSpec — Plot horizontal lines at each y from xmin to xmax.fillPlotFillSpec — Plot filled polygons.axhLinePlotAxhLineSpec — Add a horizontal line across the axis.axhSpanPlotAxhSpanSpec — Add a horizontal span (rectangle) across the axis.axvLinePlotAxvLineSpec — Add a vertical line across the axes.axvSpanPlotAxvSpanSpec — Add a vertical span (rectangle) across the axes.aCorrPlotACorrSpec — Plot the autocorrelation of x.angleSpectrumPlotAngleSpectrumSpec — Plot the angle spectrum.coherePlotCohereSpec — Plot the coherence between x and y.csdPlotCsdSpec — Plot the cross-spectral density.magnitudeSpectrumPlotMagnitudeSpectrumSpec — Plot the magnitude spectrum.phaseSpectrumPlotPhaseSpectrumSpec — Plot the phase spectrum.psdPlotPsdSpec — Plot the power spectral density.specgramPlotSpecgramSpec — Plot a spectrogram.xCorrPlotXCorrSpec — Plot the cross correlation between x and y.boxPlotPlotBoxPlotSpec — Make a box and whisker plot.violinPlotPlotViolinPlotSpec — Make a violin plot.violinPlotViolinSpec — Drawing function for violin plots.bxpPlotBxpSpec — Drawing function for box and whisker plots.hexBinPlotHexBinSpec — Make a hexagonal binning plot.histPlotHistSpec — Plot a histogram.hist2dPlotHist2dSpec — Make a 2D histogram plot.cLabelPlotCLabelSpec — Label a contour plot.contourPlotContourSpec — Plot contours.contourFPlotContourFSpec — Plot contours.matShowPlotMatShowSpec — Plot the values of a 2D matrix or array as color-coded image.pColorPlotPColorSpec — Create a pseudocolor plot with a non-regular rectangular grid.pColorFastPlotPColorFastSpec — Create a pseudocolor plot with a non-regular rectangular grid.pColorMeshPlotPColorMeshSpec — Create a pseudocolor plot with a non-regular rectangular grid.spyPlotSpySpec — Plot the sparsity pattern on a 2-D array.