1.1 图形控件的使用-文本框组件
import streamlit as st
import pandas as pd
from sympy import latex
from twisted.plugins.twisted_reactors import select
df = pd.DataFrame({
'col1':[1,2,3],
'col2':[4,5,6],
'col3':[7,8,9],
'col4':[10,11,12]
})
st.markdown('# 1.streamlit入门')
st.markdown('## 1.1 图形控件的使用-文本框组件')
st.text('这是最基本的文本框组件,可以用于输入基本的文本内容')
st.write('你好啊')
st.latex(r"基本LATEX公式:E=mc^2")
image.png
1.2 显示matplotlib图像
import streamlit as st
import matplotlib.pyplot as plt
import numpy as np
# 设置点的个数
m = 20
n = 256 * m + 1 # 总点数
# 变量的取值范围
tx = np.linspace(0, 24 * np.pi, n)
# 初始化 x 和 y 数组
x = np.zeros(n)
y = np.zeros(n)
# 计算函数的值
for i in range(n):
t = tx[i]
x[i] = np.sin(t) * (np.exp(np.cos(t)) - 2 * np.cos(4 * t) - (np.sin(t / 12))**5)
y[i] = np.cos(t) * (np.exp(np.cos(t)) - 2 * np.cos(4 * t) - (np.sin(t / 12))**5)
fig = plt.figure(figsize=(8, 6), dpi=100)
plt.plot(x,y, color='orange')
plt.xlabel('This is x label')
plt.ylabel('This is y label')
plt.title('The subplot of figure')
st.pyplot(fig)