Skip to content
Jeremy Faden edited this page Jul 20, 2023 · 6 revisions

Introduction

This wiki provides more documentation of the python-autoplot interface. It is described briefly here, but there are many features found with this interface (as all of Autoplot is available to Python) and this document will describe them.

Loading data into Python using Autoplot

from autoplot import *

# Download autoplot.jar if needed and return Python bridge object
javaaddpath('http://autoplot.org/latest/autoplot.jar')
  
# Create Autoplot Data Set
apds = APDataSet()

# Set URI
apds.setDataSetURI('http://autoplot.org/data/swe-np.xls?column=data&depend0=dep0')

# Get the data
apds.doGetDataSet()

print(apds.toString())
# http://autoplot.org/data/swe-np.xls?column=data&depend0=dep0
# data: data[dep0=288] (dimensionless)
# dep0: dep0[288] (days since 1899-12-30T00:00:00.000Z) (DEPEND_0)

# Extract data values
vv = to_ndarray(apds, 'data')
tt = to_ndarray(apds, 'dep0')

from matplotlib import pyplot as plt
plt.plot(tt,vv)
plt.show()

Plotting from Python to Autoplot

The typical use for the library is to provide Autoplot's data loading to Python, but it can also be used to provide plotting to Python.

First, you will need a running Autoplot with it's server started. Start Autoplot using your preferred method, then on the menubar, select Options->"Enable Feature"->"Server" and press okay with the port 12345. This tells Autoplot to listen to commands on that port. Python will write temporary files from your data and send plot commands to Autoplot.

from autoplot import autoplot
autoplot.applot([1,2,3,4,5,6,7],[4,5,6,4,5,6,7])  # plots using the default plot.
autoplot.applot(1,[1,2,3,4,5,6,7],[4,5,6,4,5,6,7])  # adds a plot which is identified as plot #1
autoplot.load('https://github.com/autoplot/dev/demos/tools/layout/2v_2h.vap')
for i in range(4): autoplot.applot(i,[1,2,3,4,5,6,7],[4,5,6,4,5,6,7]) 

Starting Autoplot from Python

We can leverage the Python code distribution system pip to distribute the Autoplot single jar and launch into it from Python.

import autoplot
autoplot.start('20230720a')  # v2023a_8 is the first version which will support this, and then a no-arg call can be used.