Data Visualization

Bodo supports Matplotlib visualization natively inside JIT functions. This section specifies the supported Matplotlib APIs and classes. In general, these APIs support all arguments except for the restrictions specified in each section.

Plotting APIs

Currently, Bodo automatically supports the following plotting APIs.

These APIs have the following restrictions:

  • The data being plotted must be Numpy arrays and not Pandas data structures.

  • Use of lists is not currently supported. If you need to plot multiple arrays use a tuple or a 2D Numpy array.

These functions work by automatically gathering all of the data onto one machine and then plotting the data. If there is not enough memory on your machine, a sample of the data can be selected. The example code below demonstrates calling plot with a sample of the data:

import matplotlib.pyplot as plt

%matplotlib inline

@bodo.jit
def dist_plot(n):
    X = np.arange(n)
    Y = np.exp(-X/3.0)
    plt.plot(X[::10], Y[::10]) # gather every 10th element
    plt.show()

dist_plot(100)
[output:0]
../../_images/bodo_tutorial_83_1.png

Formatting APIs

In addition to plotting, we also support a variety of formatting APIs to modify your figures.

In general these APIs support all arguments except for the restrictions specified. In addition, APIs have the following restrictions:

  • Use of lists is not currently supported. If you need to provide a list, please use a tuple instead.

  • Formatting functions execute on all ranks by default. If you need to execute further Matplotlib code on all of your processes, please close any figures you opened inside Bodo.

Matplotlib Classes

Bodo supports the following Matplotlib classes when used with the previously mentioned APIs:

Working with Unsupported APIs

For other visualization functions, you can call them from regular Python and manually gather the data. If the data does not fit in a single machine’s memory, you may need to take a sample. The example code below demonstrates gathering a portion of data in Bodo and calling polar (which Bodo doesn’t support yet) in regular Python:

import bodo
import numpy as np
import matplotlib.pyplot as plt

@bodo.jit()
def dist_gather_test(n):
    X = np.arange(n)
    Y = 3 - np.cos(X)
    return bodo.gatherv(X[::10]), bodo.gatherv(Y[::10])  # gather every 10th element

X_Sample, Y_Sample = dist_gather_test(1000)
if bodo.get_rank() == 0:
    plt.polar(X_Sample, Y_Sample)
    plt.show()