Examples

This is a collection of rich examples supported by Hydrogen. Please share your favorite snippets with us and add them to this page.

Interactive plots using Plotly

Python
Python using matplotlib
R
from plotly import offline
offline.init_notebook_mode()

offline.iplot([{"y": [1, 2, 1]}])
import numpy as np
import matplotlib.pyplot as plt
from plotly import offline as py
import plotly.tools as tls
py.init_notebook_mode()

t = np.linspace(0, 20, 500)
plt.plot(t, np.sin(t))

plotly_fig = tls.mpl_to_plotly(plt.gcf())
py.iplot(plotly_fig)
library(IRdisplay)

data <- list(list(x=c(1999, 2000, 2001, 2002), y=c(10, 15, 13, 17), type='scatter'))
figure <- list(data=data)

mimebundle <- list('application/vnd.plotly.v1+json'=figure)
IRdisplay::publish_mimebundle(mimebundle)

Interactive JSON Objects

Python
from IPython.display import JSON

data = {"foo": {"bar": "baz"}, "a": 1}
JSON(data)

Static plots

With support for svg, png, jpeg and gif

Python using matplotlib
import matplotlib.pyplot as plt
import numpy as np

%matplotlib inline
%config InlineBackend.figure_format = 'svg'
t = np.linspace(0, 20, 500)

plt.plot(t, np.sin(t))
plt.show()

LaTeX

Python using sympy
Python using Math
Python using Latex
import sympy as sp
sp.init_printing(use_latex='mathjax')

x, y, z = sp.symbols('x y z')
f = sp.sin(x * y) + sp.cos(y * z)
sp.integrate(f, x)
from IPython.display import Math

Math(r'i\hbar \frac{dA}{dt}~=~[A(t),H(t)]+i\hbar \frac{\partial A}{\partial t}.')
from IPython.display import Latex
Latex('''The mass-energy equivalence is described by the famous equation

$$E=mc^2$$

discovered in 1905 by Albert Einstein.
In natural units ($c$ = 1), the formula expresses the identity

\\begin{equation}
E=m
\\end{equation}''')

Data frames

Python using pandas
Python using numpy
import numpy as np
import pandas as pd

df = pd.DataFrame({'A': 1.,
                   'B': pd.Timestamp('20130102'),
                   'C': pd.Series(1, index=list(range(4)), dtype='float32'),
                   'D': np.array([3] * 4, dtype='int32'),
                   'E': pd.Categorical(["test", "train", "test", "train"]),
                   'F': 'foo'})

df
import numpy as np

t = np.linspace(0, 20, 500)
t

Images

Python
from IPython.display import Image
Image('http://jakevdp.github.com/figures/xkcd_version.png')

HTML

Python
from IPython.display import HTML
HTML("<iframe src='https://nteract.io/' width='900' height='490'></iframe>")

Plain Text

Python
JavaScript
print("Hello World!")
console.log("Hello World!");

results matching ""

    No results matching ""