本帖最后由 苏紫方璇 于 2024-6-24 11:55 编辑
[Python] 纯文本查看 复制代码 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) |