Showing posts with label plot.ly. Show all posts
Showing posts with label plot.ly. Show all posts

Wednesday, July 10, 2013

plot.ly now has an API


By Vasudev Ram

I had blogged a couple of times earlier about plot.ly, here:

plot.ly, fast plotting in the browser

and here:

Plot me some randomness

Saw today via Twitter that plot.ly now has an API: plot.ly API

The current Hacker News thread about plot.ly has co-founder cparmer participating. He says in a comment in that thread, that after they first released plot.ly, 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 plot.ly 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 plot.ly module for Python via pip (or other methods).

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

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

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

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

# Para 1
username='v.ram'
email='[email protected]'
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 plot.ly

# 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 https://plot.ly/~v.ram/0 or inside your plot.ly account where it is named 'plot from API'
url: https://plot.ly/~v.ram/0
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 plot.ly API is new, but it looks useful and worth checking out.

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




- Vasudev Ram - Dancing Bison Enterprises

Contact me

Wednesday, April 24, 2013

Plot me some randomness


By Vasudev Ram

In this recent post about plot.ly,

plot.ly, fast plotting in the browser,

I mentioned that plotting by pasting data worked, but plotting using Python had an issue, and that they said they were fixing it.

The plot.ly people got back to me saying that the Python issue is fixed.

I tried it out again with a couple of simple plotting examples involving random numbers. They worked.

Here are the examples:

from numpy import *
from random import randint

x = range(1, 10)
y = [ random.randint(1, 10) for i in x ]
plot(x, y)

from numpy import *
from random import randint

x = range(1, 20)
y = [ random.randint(1, 10) for i in x ]
plot(x, y)

(The only difference in the above two scripts is 10 vs 20.)

You can try out that code, or your own, in plot.ly.

Go to https://plot.ly/plot.

Click on the "tab" labeled "+" near the top left of the screen, then click "Script" from the drop-down menu.

Enter your script (no need to Save) and then click Run.

If your code has no errors, your plot will appear in a new tab (not a new browser tab, but a new "tab" within the plot.ly browser tab).

The plot may take 2 to 3 seconds to appear.

plot.ly is beta software, but looks useful. They have many more complex examples in their demos.


- Vasudev Ram - Dancing Bison Enterprises


Friday, March 29, 2013

plot.ly, fast plotting in the browser

By Vasudev Ram

I got to know about plot.ly via this PyCon blog post about Startup Row selections for PyCon US 2013.

Then I tried it out. plot.ly enables you to create plots in your browser. They support plotting data via entering it, importing it from a file, or programming the plot in Python - the Python method seems to be fairly simple, conceptually, at least for simple plots.

I first tried it out using the Python method, but it did not work. No error message, but not output was displayed. Then I tried it out using the method of copy-pasting some data into the screen, and that method worked; it instantly created a plot.

I wrote to them about the problem with the Python plotting method, and one of the founders, Jack, replied, saying they currently have some issue with that. They are working on it.

Once they solve the issue, it may be a useful way of plotting using Python in the browser.

About plot.ly

- Vasudev Ram - Dancing Bison Enterprises