{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Overview\n", "plotly.py 3.4.0 now support $\\LaTeX$ typesetting in the Jupyter Notebook!" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import plotly.graph_objs as go\n", "import plotly.io as pio" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "trace1 = go.Scatter(\n", " x=[1, 2, 3, 4],\n", " y=[1, 4, 9, 16],\n", " name='$\\\\alpha_{1c} = 352 \\\\pm 11 \\\\text{ km s}^{-1}$'\n", ")\n", "trace2 = go.Scatter(\n", " x=[1, 2, 3, 4],\n", " y=[0.5, 2, 4.5, 8],\n", " name='$\\\\beta_{1c} = 25 \\\\pm 11 \\\\text{ km s}^{-1}$'\n", ")\n", "data = [trace1, trace2]\n", "layout = go.Layout(\n", " title='$\\LaTeX \\\\text{ Typesetting}$',\n", " xaxis=dict(\n", " title='$\\\\sqrt{(n_\\\\text{c}(t|{T_\\\\text{early}}))}$'\n", " ),\n", " yaxis=dict(\n", " title='$d, r \\\\text{ (solar radius)}$'\n", " )\n", ")\n", "fig = go.FigureWidget(data=data, layout=layout)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "bf2b512d29b544d4a751e1063532a6c9", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FigureWidget({\n", " 'data': [{'name': '$\\\\alpha_{1c} = 352 \\\\pm 11 \\\\text{ km s}^{-1}$',\n", " 'type': …" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It's also possible to save a figure with $\\LaTeX$ typesetting to an HTML file. To do so, set the `include_mathjax` argument to `'cdn'` in the `plotly.offline.plot` function" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "from plotly.offline import plot" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'file:///Users/jmmease/Plotly/repos/plotly.py_release_notebooks/notebooks/v3.4.0/fig_with_LaTeX.html'" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plot(fig, filename='fig_with_LaTeX.html', include_mathjax='cdn')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.7" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": { "bf2b512d29b544d4a751e1063532a6c9": { "model_module": "plotlywidget", "model_module_version": "^0.5.0-rc.1", "model_name": "FigureModel", "state": { "_data": [ { "name": "$\\alpha_{1c} = 352 \\pm 11 \\text{ km s}^{-1}$", "type": "scatter", "uid": "632b8245-f0a6-42e3-a16b-9afb1dae8d0c", "x": [ 1, 2, 3, 4 ], "y": [ 1, 4, 9, 16 ] }, { "name": "$\\beta_{1c} = 25 \\pm 11 \\text{ km s}^{-1}$", "type": "scatter", "uid": "5c1b32ca-8526-4aa9-9c96-403475eda27a", "x": [ 1, 2, 3, 4 ], "y": [ 0.5, 2, 4.5, 8 ] } ], "_js2py_pointsCallback": {}, "_js2py_relayout": {}, "_js2py_restyle": {}, "_js2py_update": {}, "_layout": { "template": {}, "title": "$\\LaTeX \\text{ Typesetting}$", "xaxis": { "title": "$\\sqrt{(n_\\text{c}(t|{T_\\text{early}}))}$" }, "yaxis": { "title": "$d, r \\text{ (solar radius)}$" } }, "_py2js_addTraces": {}, "_py2js_animate": {}, "_py2js_deleteTraces": {}, "_py2js_moveTraces": {}, "_py2js_removeLayoutProps": {}, "_py2js_removeTraceProps": {}, "_py2js_restyle": {}, "_py2js_update": {}, "_view_count": 1 } } }, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 2 }