Wednesday, July 10, 2013 now has an API

By Vasudev Ram

I had blogged a couple of times earlier about, here:, fast plotting in the browser

and here:

Plot me some randomness

Saw today via Twitter that now has an API: API

The current Hacker News thread about has co-founder cparmer participating. He says in a comment in that thread, that after they first released, the top request was for an API. They have now released it, with support for Python, MATLAB, R and Arduino.

Took a look at the API page and it looks interesting.

Excerpt from the page:

[ Send data to your Plotly account from your desktop environment through our APIs and view your plot at a unique URL. Available for Python, R, MATLAB, and Arduino. ]

You can install the module for Python via pip (or other methods).

After that you can generate a plot from code on your desktop via the API and then get back a link/URL to the plot on the site.

An interesting feature is that you can sign up programmatically via the API.

Here is an example program using the API, only slightly modified from their docs:

# One-time stuff to import plotly, and sign up via the API.
import plotly

# Para 1
response = plotly.signup(username, email)
api_key = response['api_key']
tmp_pw = response['tmp_pw']
print "api_key:", api_key
print "tmp_pw:", tmp_pw

# Stuff that can repeat/vary, to use

# Para 2
py = plotly.plotly(username='v.ram', key='obscured')

x0 = ['giraffes', 'orangutans', 'monkeys']
y0 = [20, 14, 23]
data = {'x': x0, 'y': y0,
 'type': 'bar'}
response = py.plot([data])
url = response['url']
filename = response['filename']
print "url:", url
print "filename:", filename

And here is the output from running that program:
High five! You successfuly sent some data to your account on plotly. View your plot in your browser at or inside your account where it is named 'plot from API'
filename: plot from API
I then pasted the link above in my browser and it showed the plot.

You will have to change the values in the above code for username and email, to values of your own, and then run the program.

Of course, the API is new, but it looks useful and worth checking out.

Here is a screenshot of the plot generated by the above Python code:

- Vasudev Ram - Dancing Bison Enterprises

Contact me

No comments: