Quentin Bammey
9th of February, 2022
Convey the results of experiments (Jupyter notebook) with multiple medias:
Great article on the subject here
# Helix equation
t = np.linspace(0, 20, 100)
x, y, z = np.cos(t), np.sin(t), t
fig = go.Figure(data=[go.Scatter3d(
x=x,
y=y,
z=z,
mode='markers',
marker=dict(
size=12,
color=z, # set color to an array/list of desired values
colorscale='Viridis', # choose a colorscale
opacity=0.8
)
)])
# tight layout
fig.update_layout(margin=dict(l=0, r=0, b=0, t=0))
fig.show()
Limitation: matplotlib figures are not rendered as interactive!
from sklearn.manifold import TSNE
df = px.data.iris()
features = df.loc[:, :'petal_width']
tsne = TSNE(n_components=3, random_state=0, learning_rate='auto', init='random')
projections = tsne.fit_transform(features)
fig = px.scatter_3d(
projections, x=0, y=1, z=2,
color=df.species, labels={'color': 'species'}
)
fig.update_traces(marker_size=8)
fig.show()
Compared to Plotly: interactivity needs to be specified manually, but works especially well with pandas dataframes
x = np.random.normal(size=100)
y = np.random.normal(size=100)
m = np.random.normal(15, 1, size=100)
source = pd.DataFrame({"x": x, "y":y, "m":m})
# interval selection in the scatter plot
pts = alt.selection(type="interval", encodings=["x"])
# left panel: scatter plot
points = alt.Chart().mark_point(filled=True, color="black").encode(
x='x',
y='y'
).transform_filter(
pts
).properties(
width=300,
height=300
)
# right panel: histogram
mag = alt.Chart().mark_bar().encode(
x='mbin:N',
y="count()",
color=alt.condition(pts, alt.value("black"), alt.value("lightgray"))
).properties(
width=300,
height=300
).add_selection(pts)
# build the chart:
alt.hconcat(
points,
mag,
data=source
).transform_bin(
"mbin",
field="m",
bin=alt.Bin(maxbins=20)
)
import bokeh as bkh
import bokeh.plotting as bkp
from bokeh.io import output_notebook
output_notebook(resources=bkh.resources.Resources(mode='cdn'), hide_banner=True)
N = 500
x = np.linspace(0, 10, N)
y = np.linspace(0, 10, N)
xx, yy = np.meshgrid(x, y)
d = np.sin(xx)*np.cos(yy)
p = bkp.figure(tooltips=[("x", "$x"), ("y", "$y"), ("value", "@image")])
p.x_range.range_padding = p.y_range.range_padding = 0
# must give a vector of image data for image parameter
p.image(image=[d], x=0, y=0, dw=10, dh=10, palette="Spectral11", level="image")
p.grid.grid_line_width = 0.5
bkp.show(p)
They work exactly the same way. You can re-use most of your code
I could go on and on, and I should probably avoid doing this too often, but if this is absolutely necessary for me to make you read way more content than you should have to read in a single slide, then I want to be able to do so, even if as a result of my blabber you end up reading this useless piece of information instead of listening to me.