Skip to content

Instantly share code, notes, and snippets.

@msund
Last active August 29, 2015 14:01
Show Gist options
  • Save msund/21be3e818625c309e3c8 to your computer and use it in GitHub Desktop.
Save msund/21be3e818625c309e3c8 to your computer and use it in GitHub Desktop.
LaTeX Graphs
{
"metadata": {
"name": "Untitled0"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": "Interactive LaTeX in Plotly"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "[Plotly](https://plot.ly) reads LaTeX and lets you make and share interactive graphs. You can edit them with Python, MATLAB, R, or from our GUI. Try out these examples with our public key, or [sign-up](https://plot.ly/ssi) and do as much free public graphing and sharing as you'd like (like GitHuB)."
},
{
"cell_type": "code",
"collapsed": false,
"input": "import plotly\nimport math\nimport random\nimport numpy as np",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": "# How you communicate with Plotly's servers\nimport plotly.plotly as py \n\n# Useful tools, e.g., get_credentials(), get_sublots()\nimport plotly.tools as tls",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 9
},
{
"cell_type": "code",
"collapsed": false,
"input": "py.sign_in(\"IPython.Demo\", \"1fw3zw2o13\")",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 10
},
{
"cell_type": "code",
"collapsed": false,
"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)",
"language": "python",
"metadata": {},
"outputs": [
{
"html": "<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\"seamless=\"seamless\" src=\"https://plot.ly/~IPython.Demo/3813\" height=\"525\" width=\"100%\"></iframe>",
"metadata": {},
"output_type": "display_data",
"text": "<IPython.core.display.HTML at 0x7ff0146d3f90>"
}
],
"prompt_number": 11
},
{
"cell_type": "code",
"collapsed": false,
"input": "x = np.linspace(0,np.pi,100)\ny1 = x;\ny2 = y1-x**3/6.\ny3 = y2+x**5/120.\ny4 = np.sin(x)\n\npy.iplot([{'x': x, 'y': y1, 'name': '$x$'},\n {'x': x, 'y': y2, 'name': '$x-\\\\frac{x^3}{6}$'},\n {'x': x, 'y': y3, 'name': '$x-\\\\frac{x^3}{6}+\\\\frac{x^5}{120}$'},\n {'x': x, 'y': y4, 'name': '$x-\\\\frac{x^3}{6}+\\\\frac{x^5}{120}+\\\\cdots = \\\\sin(x)$'}\n ], layout={'title': 'Taylor Series of $\\\\sin(x)$'})",
"language": "python",
"metadata": {},
"outputs": [
{
"html": "<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\"seamless=\"seamless\" src=\"https://plot.ly/~IPython.Demo/3815\" height=\"525\" width=\"100%\"></iframe>",
"metadata": {},
"output_type": "display_data",
"text": "<IPython.core.display.HTML at 0x7ff014689a10>"
}
],
"prompt_number": 14
},
{
"cell_type": "code",
"collapsed": false,
"input": "# CSS styling within IPython notebook\nfrom IPython.core.display import HTML\nimport urllib2\ndef css_styling():\n url = 'https://raw.githubusercontent.com/plotly/python-user-guide/master/custom.css'\n styles = urllib2.urlopen(url).read()\n return HTML(styles)\n\ncss_styling()",
"language": "python",
"metadata": {},
"outputs": [
{
"html": "<style>\n /*body {\n background-color: #F5F5F5;\n }*/\n div.cell{\n width: 850px;\n margin-left: 10% !important;\n margin-right: auto;\n }\n h1 {\n font-family: \"Open sans\",verdana,arial,sans-serif;\n }\n .text_cell_render h1 {\n font-weight: 200;\n font-size: 40pt;\n line-height: 100%;\n color:#447adb;\n margin-bottom: 0em;\n margin-top: 0em;\n display: block;\n white-space: nowrap;\n } \n h2 {\n font-family: \"Open sans\",verdana,arial,sans-serif;\n text-indent:1em;\n }\n .text_cell_render h2 {\n font-weight: 200;\n font-size: 20pt;\n font-style: italic;\n line-height: 100%;\n color:#447adb;\n margin-bottom: 1.5em;\n margin-top: 0.5em;\n display: block;\n white-space: nowrap;\n } \n h3 {\n font-family: \"Open sans\",verdana,arial,sans-serif;\n }\n .text_cell_render h3 {\n font-weight: 300;\n font-size: 18pt;\n line-height: 100%;\n color:#447adb;\n margin-bottom: 0.5em;\n margin-top: 2em;\n display: block;\n white-space: nowrap;\n }\n h4 {\n font-family: \"Open sans\",verdana,arial,sans-serif;\n }\n .text_cell_render h4 {\n font-weight: 300;\n font-size: 16pt;\n color:#447adb;\n margin-bottom: 0.5em;\n margin-top: 0.5em;\n display: block;\n white-space: nowrap;\n }\n h5 {\n font-family: \"Open sans\",verdana,arial,sans-serif;\n }\n .text_cell_render h5 {\n font-weight: 300;\n font-style: normal;\n color: #1d3b84;\n font-size: 16pt;\n margin-bottom: 0em;\n margin-top: 1.5em;\n display: block;\n white-space: nowrap;\n }\n div.text_cell_render{\n font-family: \"Open sans\",verdana,arial,sans-serif;\n line-height: 135%;\n font-size: 125%;\n width:750px;\n margin-left:auto;\n margin-right:auto;\n text-align:justify;\n text-justify:inter-word;\n }\n div.output_subarea.output_text.output_pyout {\n overflow-x: auto;\n overflow-y: scroll;\n max-height: 300px;\n }\n div.output_subarea.output_stream.output_stdout.output_text {\n overflow-x: auto;\n overflow-y: scroll;\n max-height: 300px;\n }\n code{\n font-size: 78%;\n }\n .rendered_html code{\n background-color: transparent;\n }\n ul{\n /* color:#447adb; */ // colors text too\n margin: 2em;\n }\n ul li{\n padding-left: 0.5em; \n margin-bottom: 0.5em; \n margin-top: 0.5em; \n }\n ul li li{\n padding-left: 0.2em; \n margin-bottom: 0.2em; \n margin-top: 0.2em; \n }\n ol{\n /* color:#447adb; */ // colors text too\n margin: 2em;\n }\n ol li{\n padding-left: 0.5em; \n margin-bottom: 0.5em; \n margin-top: 0.5em; \n }\n /*.prompt{\n display: None;\n } */\n ul li{\n padding-left: 0.5em; \n margin-bottom: 0.5em; \n margin-top: 0.2em; \n }\n a:link{\n font-weight: bold;\n color:#447adb;\n }\n a:visited{\n font-weight: bold;\n color: #1d3b84;\n }\n a:hover{\n font-weight: bold;\n color: #1d3b84;\n }\n a:focus{\n font-weight: bold;\n color:#447adb;\n }\n a:active{\n font-weight: bold;\n color:#447adb;\n }\n .rendered_html :link {\n text-decoration: none; \n }\n .rendered_html :hover {\n text-decoration: none; \n }\n .rendered_html :visited {\n text-decoration: none;\n }\n .rendered_html :focus {\n text-decoration: none;\n }\n .rendered_html :active {\n text-decoration: none;\n }\n .warning{\n color: rgb( 240, 20, 20 )\n } \n hr {\n color: #f3f3f3;\n background-color: #f3f3f3;\n height: 1px;\n }\n blockquote{\n display:block;\n background: #f3f3f3;\n font-family: \"Open sans\",verdana,arial,sans-serif;\n width:610px;\n padding: 15px 15px 15px 15px;\n text-align:justify;\n text-justify:inter-word;\n }\n blockquote p {\n margin-bottom: 0;\n line-height: 125%;\n font-size: 100%;\n }\n /* element.style {\n } */ \n</style>\n<script>\n MathJax.Hub.Config({\n TeX: {\n extensions: [\"AMSmath.js\"]\n },\n tex2jax: {\n inlineMath: [ [\"$\",\"$\"], [\"\\\\(\",\"\\\\)\"] ],\n displayMath: [ [\"$$\",\"$$\"], [\"\\\\[\",\"\\\\]\"] ]\n },\n displayAlign: \"center\", // Change this to \"center\" to center equations.\n \"HTML-CSS\": {\n styles: {\".MathJax_Display\": {\"margin\": 4}}\n }\n });\n</script>\n",
"metadata": {},
"output_type": "pyout",
"prompt_number": 21,
"text": "<IPython.core.display.HTML at 0x7ff014684490>"
}
],
"prompt_number": 21
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment