Skip to content

Commit 5369c89

Browse files
committed
Add Altair and streamlit examples
1 parent 789353e commit 5369c89

File tree

5 files changed

+297
-1
lines changed

5 files changed

+297
-1
lines changed

source-code/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ to create it. There is some material not covered in the presentation as well.
2424
* dash
2525

2626
## What is it?
27+
* [`altair`](altair): illustration of an interactive plot using Altair.
28+
* [`dash`](dash): illustration of creating a simple dashboard using dash.
2729
* [`db-access`](db-access): illustration of accessing SQLite databases and using
2830
SQLAlchemy, including object-relational mapping.
2931
* [`gis`](gis): illustrations of working with geospatial data, including geopandas.
@@ -35,8 +37,8 @@ to create it. There is some material not covered in the presentation as well.
3537
* [`regexes`](regexes): illustrations of using regular expressions for validation
3638
and information extraction from textual data.
3739
* [`seaborn`](seaborn): illustrations of using Seaborn to create plots.
40+
* [`streamlit`](streamlit): illustration of a simple dashboard created with streamlit.
3841
* [`web-scraping`](web-scraping): illustration of web scraping using beautiful soup
3942
and graph representation using networkx.
4043
* [`xarray`](xarray): illustrates the xarray library for pandas-like operations
4144
on multi-dimensional arrays.
42-
* [`dash`](dash): illustration of creating a simple dashboard using dash.

source-code/altair/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Altair
2+
3+
Altair is a sophisticated plotting library that lets you make highly customizalble
4+
and interactive plots.
5+
6+
7+
## What is it?
8+
9+
1. [`altair_interaction.ipynb`](altair/altair_interaction.ipynb): create a plot with
10+
hover values and an interactive legend.

source-code/altair/altair_interaction.ipynb

Lines changed: 238 additions & 0 deletions
Large diffs are not rendered by default.

source-code/streamlit/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# streamlit
2+
3+
streamlit is a framework for creating dashboards.
4+
5+
6+
## What is it?
7+
8+
1. [`distributions.py`](distributions.py): dashboard that displays a sample from a
9+
user-selected probability distribution.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python
2+
3+
import matplotlib.pyplot as plt
4+
import numpy as np
5+
import streamlit as st
6+
7+
# This is markdown that will be displayed automatically (magic commands)
8+
'''
9+
# Distribution tester
10+
11+
Pick a probability distribution from the list and we shall draw the a
12+
histogram for a random sample from the selected distribution.
13+
'''
14+
15+
# Make some choices for a user to select
16+
keys = ['Normal','Uniform']
17+
dist_key = st.selectbox('Which Distribution do you want to plot?',keys)
18+
19+
# Logic of our program
20+
if dist_key == 'Normal':
21+
'''
22+
Select the mean value $\mu$ and the standard deviation $\sigma$ using the
23+
sliders.
24+
'''
25+
mu = st.slider('mu', min_value=-2.0, max_value=2.0, value=0.0, step=0.25)
26+
sigma = st.slider('sigma', min_value=0.0, max_value=5.0, value=1.0, step=0.25)
27+
nums = np.random.normal(loc=mu, scale=sigma, size=1000)
28+
elif dist_key == 'Uniform':
29+
nums = np.random.uniform(0.0, 2.0, size=1000)
30+
31+
# Display data
32+
figure, axes = plt.subplots()
33+
axes.hist(nums, bins=20)
34+
axes.set_xlabel('$x$')
35+
axes.set_ylabel('$P(x)$')
36+
37+
st.pyplot(figure)

0 commit comments

Comments
 (0)