Skip to content
Jeremy Faden edited this page Jul 15, 2024 · 7 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

import autoplot as ap

ap.init()

apds= ap.getDataSet('http://autoplot.org/data/swe-np.xls?column=data&depend0=dep0')

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 = ap.to_ndarray(apds, 'data')
tt = ap.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.

import autoplot as ap
ap.applot([1,2,3,4,5,6,7],[4,5,6,4,5,6,7])  # plots using the default plot.
ap.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
ap.load('https://github.com/autoplot/dev/demos/tools/layout/2v_2h.vap')
for i in range(4): ap.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
ap.start('20230720a')