streamlit 构建勾股定理
本帖最后由 苏紫方璇 于 2024-6-24 11:55 编辑import streamlit as st
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Polygon
# 隐藏made with streamlit
hide_streamlit_style = """
<style>
MainMenu {visibility: hidden;}
footer {visibility: hidden;}
</style>
"""
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
a = st.sidebar.slider('a边', 0, 10, value=None, step=None)
b = st.sidebar.slider('b边', 0, 10, value=None, step=None)
st.write((a*a+b*b)**0.5)
# 定义三角形的三个顶点
vertices = [(0, 0), (0, a), (b, 0)]
# 设置X、Y、Z面的背景是白色
plt.rcParams['figure.facecolor'] = 'none'
# 创建画布和坐标轴
fig, ax = plt.subplots()
# 使用Polygon绘制三角形
ax.add_patch(Polygon(vertices, color='pink', alpha=0.5))
# 隐藏坐标轴
ax.axis('off')
# 设置坐标轴的范围
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
# 显示图形
# plt.show()
st.pyplot(fig) 学习了,谢谢 学而忘之也 插入代码可以参考这个帖子
【公告】发帖代码插入以及添加链接教程(有福利)
https://www.52pojie.cn/thread-713042-1-1.html
(出处: 吾爱破解论坛)
页:
[1]