Skip to content

Commit 3014768

Browse files
committed
Create Plotly gets Latex-y
1 parent c34486e commit 3014768

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

Plotly gets Latex-y

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
{
2+
"metadata": {
3+
"name": "LaTeX in Plotly graphs"
4+
},
5+
"nbformat": 3,
6+
"nbformat_minor": 0,
7+
"worksheets": [
8+
{
9+
"cells": [
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": "<h1>Plotly graphs with LaTeX</h1>"
14+
},
15+
{
16+
"cell_type": "markdown",
17+
"metadata": {},
18+
"source": "<h4>IPython supports lovely Latex typesetting through <a href=\"http://www.mathjax.org/\">MathJax:</a></h4>"
19+
},
20+
{
21+
"cell_type": "markdown",
22+
"metadata": {},
23+
"source": "$$\\sum_{k=0}^{\\infty} \\frac {(-1)^k x^{1+2k}}{(1 + 2k)!}$$"
24+
},
25+
{
26+
"cell_type": "markdown",
27+
"metadata": {},
28+
"source": "<h4>And Plotly has jumped on the boat! Plotly graphs now process Latex markup. Below are some examples.<br><br>Questions? Issues? jack [at] plot [dot] ly</h4>"
29+
},
30+
{
31+
"cell_type": "code",
32+
"collapsed": false,
33+
"input": "import plotly\nimport math\nimport random\nimport numpy as np",
34+
"language": "python",
35+
"metadata": {},
36+
"outputs": [],
37+
"prompt_number": 73
38+
},
39+
{
40+
"cell_type": "markdown",
41+
"metadata": {},
42+
"source": "<h4>To get hooked up with a free Plotly account, go <a href=\"https://plot.ly/api/python\">here</a></h4>"
43+
},
44+
{
45+
"cell_type": "code",
46+
"collapsed": false,
47+
"input": "un='jackp'\nk='11m2qbzob9'\npy = plotly.plotly(username=un, key=k)",
48+
"language": "python",
49+
"metadata": {},
50+
"outputs": [],
51+
"prompt_number": 4
52+
},
53+
{
54+
"cell_type": "markdown",
55+
"metadata": {},
56+
"source": "<h2>Example 1: Taylor Series for Sine</h2>"
57+
},
58+
{
59+
"cell_type": "code",
60+
"collapsed": false,
61+
"input": "def sin(x,n):\n\tsine = 0\n\tfor i in range(n):\n\t\tsign = (-1)**i\n\t\tsine = sine + ((x**(2.0*i+1))/math.factorial(2*i+1))*sign\n\treturn sine\n\nx = np.arange(-12,12,0.1)\n\nanno = {\n 'text': '$\\\\sum_{k=0}^{\\\\infty} \\\\frac {(-1)^k x^{1+2k}}{(1 + 2k)!}$',\n 'x': 0.3, 'y': 0.6,'xref': \"paper\", 'yref': \"paper\",'showarrow': False,\n 'font':{'size':24}\n}\n\nl = {\n 'annotations': [anno], \n 'title': 'Taylor series of sine',\n 'xaxis':{'ticks':'','linecolor':'white','showgrid':False,'zeroline':False},\n 'yaxis':{'ticks':'','linecolor':'white','showgrid':False,'zeroline':False},\n 'legend':{'font':{'size':16},'bordercolor':'white','bgcolor':'#fcfcfc'}\n}\n\npy.iplot([{'x':x, 'y':sin(x,1), 'line':{'color':'#e377c2'}, 'name':'$x\\\\\\\\$'},\\\n {'x':x, 'y':sin(x,2), 'line':{'color':'#7f7f7f'},'name':'$ x-\\\\frac{x^3}{6}$'},\\\n {'x':x, 'y':sin(x,3), 'line':{'color':'#bcbd22'},'name':'$ x-\\\\frac{x^3}{6}+\\\\frac{x^5}{120}$'},\\\n {'x':x, 'y':sin(x,4), 'line':{'color':'#17becf'},'name':'$ x-\\\\frac{x^5}{120}$'}], layout=l)",
62+
"language": "python",
63+
"metadata": {},
64+
"outputs": [
65+
{
66+
"output_type": "stream",
67+
"stream": "stdout",
68+
"text": "\n\n\n"
69+
},
70+
{
71+
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~jackp/1404/600/600\" width=\"650\"></iframe>",
72+
"metadata": {},
73+
"output_type": "pyout",
74+
"prompt_number": 68,
75+
"text": "<IPython.core.display.HTML at 0x1037c7490>"
76+
}
77+
],
78+
"prompt_number": 68
79+
},
80+
{
81+
"cell_type": "markdown",
82+
"metadata": {},
83+
"source": "<h2>Example 2: Colors, Size, and Opacity</h2>"
84+
},
85+
{
86+
"cell_type": "code",
87+
"collapsed": false,
88+
"input": "identity_of_ramanujan = '$ \\\\frac{1}{\\\\Bigl(\\sqrt{\\\\phi \\\\sqrt{5}}-\\\\phi\\\\Bigr) e^{\\\\frac25 \\\\pi}} = 1+\\\\frac{e^{-2\\\\pi}} {1+\\\\frac{e^{-4\\\\pi}} {1+\\\\frac{e^{-6\\\\pi}}{1+\\\\frac{e^{-8\\\\pi}} {1+\\\\ldots} } } } $'\nannotations = []\n\nfor i in range(17):\n x = random.random()\n y = random.random()\n s = random.random()*36 \n o = random.random()\n c = random.randint(0,4)\n colors = ['#9467bd', '#17becf', '#e377c2', '#bcbd22', '#17becf' ]\n anno = {\n 'text': identity_of_ramanujan,\n 'x': x, 'y': y,'xref': \"paper\", 'yref': \"paper\",'showarrow': False,\n 'opacity':o,'font':{'size':s,'color':colors[c]}\n }\n annotations.append(anno)\n\nl = {\n 'annotations': annotations, \n 'title': '$\\\\LaTeX$',\n 'titlefont': {'size':32},\n 'xaxis':{'showticklabels':False,'ticks':'','linecolor':'white','showgrid':False,'zeroline':False},\n 'yaxis':{'showticklabels':False,'ticks':'','linecolor':'white','showgrid':False,'zeroline':False},\n 'legend':{'font':{'size':16},'bordercolor':'white','bgcolor':'#fcfcfc'}\n}\n \npy.iplot([{}], layout=l)",
89+
"language": "python",
90+
"metadata": {},
91+
"outputs": [
92+
{
93+
"output_type": "stream",
94+
"stream": "stdout",
95+
"text": "\n\n\n"
96+
},
97+
{
98+
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~jackp/1382/600/600\" width=\"650\"></iframe>",
99+
"metadata": {},
100+
"output_type": "pyout",
101+
"prompt_number": 112,
102+
"text": "<IPython.core.display.HTML at 0x102357750>"
103+
}
104+
],
105+
"prompt_number": 112
106+
}
107+
],
108+
"metadata": {}
109+
}
110+
]
111+
}

0 commit comments

Comments
 (0)