Skip to content

Instantly share code, notes, and snippets.

@arsenovic
Created January 11, 2014 18:57
Show Gist options
  • Save arsenovic/8375182 to your computer and use it in GitHub Desktop.
Save arsenovic/8375182 to your computer and use it in GitHub Desktop.
matplotlib to plotly demo
{
"metadata": {
"name": "Plotly Demo"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": "from pylab import * \nimport plotly\n#py = plotly.plotly('me', 'mykey')\n\n\ndef to_plotly(ax=None):\n '''\n converts a matplotlib plot to a inline plotly plot. \n '''\n if ax is None:\n ax = gca()\n \n lines = []\n for line in ax.get_lines():\n lines.append({'x': line.get_xdata(),\n 'y': line.get_ydata(),\n 'name': line.get_label(),\n })\n \n \n layout = {'title':ax.get_title(),\n 'xaxis':{'title':ax.get_xlabel()},\n 'yaxis':{'title':ax.get_ylabel()}\n }\n filename = ax.get_title() if ax.get_title() != '' else 'Untitled'\n print filename\n close('all')\n #return lines, layout\n return py.iplot(lines,layout=layout, filename = filename) \n\n\n\nplot(rand(100), label = 'trace1')\nplot(rand(100)+1, label = 'trace2')\ntitle('Title')\nxlabel('X label')\nylabel('Y label ')\n\nresponse = to_plotly()\nresponse ",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "Title\n"
},
{
"html": "<iframe height=\"500\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~arsenovic/10/600/450\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 44,
"text": "<IPython.core.display.HTML at 0xc290550>"
}
],
"prompt_number": 44
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment