import plotly plotly.__version__ import matplotlib.pyplot as plt # side-stepping mpl's backend import plotly.plotly as py import plotly.tools as tls from plotly.graph_objs import * %matplotlib inline py.sign_in("IPython.Demo", "1fw3zw2o13") fig1 = plt.figure() import matplotlib.pyplot as plt import numpy as np x = np.linspace(-2.0, 2.0, 10000) # The x-values sigma = np.linspace(0.4, 1.0, 4) # Some different values of sigma # Here we evaluate a Gaussians for each sigma gaussians = [(2*np.pi*s**2)**-0.5 * np.exp(-0.5*x**2/s**2) for s in sigma] ax = plt.axes() for s,y in zip(sigma, gaussians): ax.plot(x, y, lw=1.25, label=r"$\sigma = %3.2f$"%s) formula = r"$y(x)=\frac{1}{\sqrt{2\pi\sigma^2}}e^{-\frac{x^2}{2\sigma^2}}$" ax.text(0.05, 0.80, formula, transform=ax.transAxes, fontsize=20) ax.set_xlabel(r"$x$", fontsize=18) ax.set_ylabel(r"$y(x)$", fontsize=18) ax.legend() plt.show() py.iplot_mpl(fig1) from plotly.graph_objs import Data, Layout, Figure help(Figure) # Convert MPL figure to Plotly my_fig = tls.mpl_to_plotly(fig1) # Take a quick look at the Plotly representation of the MPL figure print my_fig.to_string() # Strip out the data from the Figure my_data = my_fig.get_data() my_data py.iplot_mpl(fig1, strip_style = True) tls.embed('MattSundquist', '1559') library(plotly) p <- plotly(username="MattSundquist", key="c6393zudwx") trace1 <- list( x = c(1, 2, 3, 4), y = c(1, 4, 9, 16), name = "$\alpha_{1c} = 352 \pm 11 \text{ km s}^{-1}$", type = "scatter" ) trace2 <- list( x = c(1, 2, 3, 4), y = c(0.5, 2, 4.5, 8), name = "$\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}$", type = "scatter" ) data <- list(trace1, trace2) layout <- list( xaxis = list(title = "$\sqrt{(n_\text{c}(t|{T_\text{early}}))}$"), yaxis = list(title = "$d, r \text{ (solar radius)}$") ) response <- p$plotly(data, kwargs=list(layout=layout, filename="latex", fileopt="overwrite")) url <- response$url filename <- response$filename tls.embed('MattSundquist', '613') zeta = [0.01 .02 0.05 0.1 .2 .5 1 ]; colors = ['r' 'g' 'b' 'c' 'm' 'y' 'k']; w = logspace(-1, 1, 1000); figure; for i = 1:7 a = w.^2 - 1; b = 2*w*zeta(i); gain = sqrt(1./(a.^2 + b.^2)); loglog(w, gain, 'color', colors(i), 'linewidth', 2); hold on; end % Set the axis limits axis([0.1 10 0.01 100]); % title and labels title('|G|(\omega) vs \omega'); xlabel('\omega'); ylabel('|G|(\omega)'); fig2plotly() tls.embed('MATLAB-Demos', '4') # CSS styling within IPython notebook from IPython.core.display import HTML import urllib2 def css_styling(): url = 'https://raw.githubusercontent.com/plotly/python-user-guide/master/custom.css' styles = urllib2.urlopen(url).read() return HTML(styles) css_styling()