LaTeX in Python/v3
How to add LaTeX to python graphs.
Note: this page is part of the documentation for version 3 of Plotly.py, which is not the most recent version.
See our Version 4 Migration Guide for information about how to upgrade.
The version 4 version of this page is here.
See our Version 4 Migration Guide for information about how to upgrade.
The version 4 version of this page is here.
New to Plotly?¶
Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!
Version Check¶
Plotly's python package is updated frequently. Run pip install plotly --upgrade
to use the latest version.
In [1]:
import plotly
plotly.__version__
Out[1]:
LaTeX Typesetting¶
In [2]:
import plotly.plotly as py
import plotly.graph_objs as go
trace1 = go.Scatter(
x=[1, 2, 3, 4],
y=[1, 4, 9, 16],
name=r'$\alpha_{1c} = 352 \pm 11 \text{ km s}^{-1}$'
)
trace2 = go.Scatter(
x=[1, 2, 3, 4],
y=[0.5, 2, 4.5, 8],
name=r'$\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}$'
)
data = [trace1, trace2]
layout = go.Layout(
xaxis=dict(
title=r'$\sqrt{(n_\text{c}(t|{T_\text{early}}))}$'
),
yaxis=dict(
title=r'$d, r \text{ (solar radius)}$'
)
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='latex')
Out[2]: