有人能帮我把它变成一个循环吗?我只是想检查一下它是否可以循环。
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)
是的。试试这个。
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
替换为类似c1
的列名。st
是对主页面的引用。c1
是对小节的引用。因此,您可以在没有with
块的情况下执行c1.text("Hello World")
。