【问题标题】:Streamlit image loop流光图像循环
【发布时间】:2021-09-09 20:12:41
【问题描述】:

谁能帮我把它做成一个循环或者它可以是一个循环?我只是想检查它是否可以循环。我是 python 和 streamlit 库的新手,呵呵。我也想在这里学习以提高自己的水平。谢谢你!

c1,c2,c3,c4,c5,c6,c7 = st.beta_columns(7)

with c1:
    fig1 = plt.figure(figsize=(14,8))
    fig1.suptitle("Gray Eqhist")
    plt.imshow(gray_eqhist, 'gray')        
    st.pyplot(fig1)
with c2:
    fig2 = plt.figure(figsize=(14,8))
    fig2.suptitle("Applied Clahe")
    plt.imshow(applied_clahe, 'gray')        
    st.pyplot(fig2)
with c3:
    fig3 = plt.figure(figsize=(14,8))
    fig3.suptitle("Binary")
    plt.imshow(thresh1, 'gray')        
    st.pyplot(fig3)
with c4:
    fig4 = plt.figure(figsize=(14,8))
    fig4.suptitle("Binary Threshold Inverted")
    plt.imshow(thresh2, 'gray')        
    st.pyplot(fig4)
with c5:
    fig5 = plt.figure(figsize=(14,8))
    fig5.suptitle("Truncated Threshold")
    plt.imshow(thresh3, 'gray')        
    st.pyplot(fig5)
with c6:
    fig6 = plt.figure(figsize=(14,8))
    fig6.suptitle("Set to 0")
    plt.imshow(thresh4, 'gray')        
    st.pyplot(fig6)
with c7:
    fig7 = plt.figure(figsize=(14,8))
    fig7.suptitle("Set to 0 Inverted")
    plt.imshow(thresh5, 'gray')        
    st.pyplot(fig7)

【问题讨论】:

  • 您可以遍历其他变量,例如您的图表和标签,并执行以下表格示例:for i in range(1, 10): cols = st.beta_columns(4) cols[0].write(f'{i}') cols[1].write(f'{i * i}') cols[2].write(f'{i * i * i}') cols[3].write('x' * i)

标签: python pandas streamlit


【解决方案1】:

是的。试试这个。


configurations = [dict(title = "Gray Eqhist",               image = gray_eqhist),
                  dict(title = "Applied Clahe",             image = applied_clahe),
                  dict(title = "Binary",                    image = thresh1),
                  dict(title = "Binary Threshold Inverted", image = thresh2),
                  dict(title = "Truncated Threshold",       image =  thresh3),
                  dict(title = "Set to 0",                  image = thresh4),
                  dict(title = "Set 0 to Invernted",        image = thresh5)]


columns = st.beta_columns(len(configurations))

for column, configuration in zip(columns, configurations):
    fig = plt.figure(figsize=(14,8))
    fig.suptitle(configuration["title"])
    plt.imshow(configuration["image"], 'gray')
    column.pyplot(fig)

您通常可以将st 替换为列名,例如c1st 是对主页的引用。 c1 是对小节的引用。所以你可以在没有with 块的情况下执行c1.text("Hello World")

【讨论】:

  • 感谢您的回答,非常感谢。我可以要求我提问吗?
  • 当然。你有什么问题? (下次有问题直接问就行了,这样更简单)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-16
  • 2012-01-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多