One of the great things about the Python language is that it talks to nearly everything. This kind of interoperability means that Plotly, which has Python bindings, can be used from a wide variety of platforms, including some you may not have thought of before.
An example is the LabVIEW development environment. LabVIEW is a software platform made by National Instruments, used widely in industry for test and measurement applications. Recently, Enthought released the Python Integration Toolkit, which is a “bridge” between the LabVIEW and Python environments.
So not only can you call Python code from LabVIEW, you can access the greater universe of Python software, including routines for signal processing, machine learning, and cloud-connected visualization like Plotly. Here’s a 2-minute introduction to the Toolkit from Eric Jones, Enthought’s CEO, speaking at National Instruments’ 2016 NI Week conference:
By writing a minimal Python “glue” module, you can call the Plotly API from LabVIEW and instantly share data to the cloud. Here’s an example LabVIEW program and the Python code which powers it. By the way, this example and others are included along with every copy of the Toolkit, so you can get started right away:
And the code it calls, which is basically “Hello World” for Plotly:
Example showing how to share data on the web using the Plot.ly
web graphing service.
To run this example, you'll first need to install the "plotly" Python
package. You can do this from the Canopy Package Manager, which can be
launched from the Canopy welcome screen.
You will also need to set up a Plot.ly account. Here's how:
This module defines one function, which takes an array of data from
LabVIEW, along with a string name, and packages the data up to send
to the Plot.ly service.
# Import a few packages so we can use their functionality.
# The main one here is "plotly", which provides Python functions that talk to
# the plot.ly web service.
import numpy as np
import plotly.plotly as py
from plotly.graph_objs import Scatter, Data
def post_to_plotly(data, name):
""" Make and share an X-Y graph using the Plot.ly web service.
The "plotly" package will also attempt to open the default web browser
when finished so we can see our data on the Web.
data: A NumPy array, from LabVIEW, with the data to plot
name: A string giving the name of the plot.
# We could also generate the X values in LabVIEW
# For this example, we'll just use 0, 1, 2...
x = np.arange(len(data))
# Send the plot request to the Plot.ly web service, and open a browser
# window to view the data
py.plot(Data([Scatter(x=x, y=data)]), filename=name)
Combining Plotly.js with Python lets you build even more sophisticated apps. For example, you can run a Python web server alongside the LabVIEW environment, and stream data to it live. Here’s the LabVIEW end of things, acquiring data from a simulated instrument:
And the Plotly dashboard, running in a local process, accessed by a web browser:
You can download the Python Integration Toolkit here to try using Plotly, Python, and LabVIEW together with your own data.
Finally, see a live demo of using Plotly as a web dashboard for LabVIEW and other examples of how Python can extend LabVIEW’s capabilities at a webinar, Thursday August 25, 2016 (1 PM CT) or Wednesday, August 31, 2016 (9 AM CT). Sign up to attend or to get a recording of a session here.