Skip to content

Instantly share code, notes, and snippets.

@kokuyokugetter
Created September 2, 2020 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kokuyokugetter/1a7ec1243f469be03fa4574c05bf5018 to your computer and use it in GitHub Desktop.
Save kokuyokugetter/1a7ec1243f469be03fa4574c05bf5018 to your computer and use it in GitHub Desktop.
streamlit CLT-dice demo
# import streamlit as st
# import pandas as pd
# import numpy as np
# """
# # 初めての Streamlit
# データフレームを表として出力できます:
# """
# df = pd.DataFrame({
# 'first column': [1, 2, 3, 4],
# 'second column': [10, 20, 30, 40]
# })
# df
# # 前のコードに下記を追加
# """
# # グラフ描画の例
# """
# chart_data = pd.DataFrame(
# np.random.randn(20, 3),
# columns=['a', 'b', 'c'])
# st.line_chart(chart_data)
# # 前のコードに下記を追加
# """
# # 地図を描画
# """
# map_data = pd.DataFrame(
# np.random.randn(1000, 2) / [50, 50] + [35.68109, 139.76719],
# columns=['lat', 'lon'])
# st.map(map_data)
# # 前のコードに下記を追加
# """
# # ウィジェットの例
# """
# if st.checkbox("チェックボックス"):
# st.write("チェックが入りました。")
# selection = st.selectbox("セレクトボックス", ["1", "2", "3"])
# st.write(f"{selection} を選択")
# """
# ## プログレスバーとボタン
# """
# import time
# if st.button("ダウンロード"):
# text = st.empty()
# bar = st.progress(0)
# for i in range(100):
# text.text(f"ダウンロード中 {i + 1}/100")
# bar.progress(i + 1)
# time.sleep(0.01)
# import streamlit as st
# import pandas as pd
# from sklearn import datasets
# @st.cache
# def load_data():
# iris = datasets.load_iris()
# df = pd.DataFrame(iris.data, columns=iris.feature_names)
# df['target'] = iris.target_names[iris.target]
# return df
# df = load_data()
# targets = list(df.target.unique())
# selected_targets = st.multiselect('select targets', targets, default=targets)
# df = df[df.target.isin(selected_targets)]
# st.dataframe(df)
import streamlit as st
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Interactive Streamlit elements, like these sliders, return their value.
# This gives you an extremely simple interaction model.
faces = st.sidebar.slider("ダイスの面数", 4, 20, 6, 1)
num = st.sidebar.slider("何個振ったか", 1, 100, 1, 1)
trials = st.sidebar.slider("試行回数", 10, 10000, 100, 10)
l = []
for i in range(trials):
data = np.random.randint(1, faces + 1, num)
l.append(np.sum(data) / num)
st.text(str(l))
# # test 用の出目の和の個数チェッカー
# l2 = [0] * (faces * num + 1)
# for i in l:
# l2[i] += 1
# for i, d in enumerate(l2):
# if i == 0:
# continue
# st.text(str(i) + ": " + str(d) + "個")
# グラフ設定
fig = plt.figure(figsize=(20,10))
st.subheader('サイコロの和の平均値の分布')
sns.distplot(l)
st.pyplot(fig)
# hist_value = np.histogram(l)[0]
# st.bar_chart(hist_value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment