In [1]:
import plotlywrapper as pw
import pandas as pd
import numpy as np
from numpy import random as rng
Now we need to generate some data to plot.
In [2]:
n = 100
X = rng.randn(100, 3)
df = pd.DataFrame(X, pd.date_range('2016', periods=n, freq=pd.DateOffset(hours=1)), columns=['alpha', 'beta', 'gamma'])
We can create scatter plots with scatter
or df.plotly.scatter
.
In [3]:
df.plotly.scatter()
Out[3]:
We can create bar charts with bar
or df.plotly.bar
.
In [4]:
df.plotly.bar()
Out[4]:
We can can show plots together simple by adding them.
In [5]:
plot = df.plotly.bar()
plot += df.plotly.line(opacity=0.7)
plot.ylabel('deliciousness')
plot.xlabel('xlabel')
Out[5]:
In [6]:
plot = pw.fill_between(ylow=X[:, 0], yhigh=X[:, 1])
plot += pw.fill_zero(X[:, 2])
plot
Out[6]:
You can also make 3D plots!
In [7]:
def fxy(x, y):
A = 1 # choose a maximum amplitude
return A*(np.cos(np.pi*x*y))**2 * np.exp(-(x**2+y**2)/2.)
L = 4
x = y = np.arange(-L/2., L/2., 0.1) # use a mesh spacing of 0.1
z = fxy(x, y[:, None])
pw.surface(x, y, z)
Out[7]:
In [8]:
t = np.linspace(0, 4*np.pi)
x = np.sin(t)
y = np.cos(t)
x2 = np.sin(t - np.pi)
y2 = np.cos(t - np.pi)
pw.line3d(x, y, t, width=20) + pw.line3d(x2, y2, t, width=20)
Out[8]:
To learn more take a look at the source!