Ludvig
commited on
Commit
·
5a49222
1
Parent(s):
224f15f
More design section
Browse files- app.py +4 -2
- design.py +84 -40
- text_sections.py +5 -0
app.py
CHANGED
|
@@ -317,7 +317,9 @@ if st.session_state["step"] >= 2:
|
|
| 317 |
predictions_are_probabilities=predictions_are_probabilities,
|
| 318 |
)
|
| 319 |
|
| 320 |
-
|
|
|
|
|
|
|
| 321 |
# TODO Fix and update these flags
|
| 322 |
element_flags = [
|
| 323 |
key
|
|
@@ -367,7 +369,7 @@ if st.session_state["step"] >= 2:
|
|
| 367 |
# The input data are counts
|
| 368 |
plotting_args += ["--n_col", f"{n_col}", "--data_are_counts"]
|
| 369 |
|
| 370 |
-
plotting_args +=
|
| 371 |
|
| 372 |
plotting_args = " ".join(plotting_args)
|
| 373 |
|
|
|
|
| 317 |
predictions_are_probabilities=predictions_are_probabilities,
|
| 318 |
)
|
| 319 |
|
| 320 |
+
# design_ready tells us whether to proceed or wait
|
| 321 |
+
# for user to fix issues
|
| 322 |
+
if st.session_state["step"] >= 3 and design_settings["design_ready"]:
|
| 323 |
# TODO Fix and update these flags
|
| 324 |
element_flags = [
|
| 325 |
key
|
|
|
|
| 369 |
# The input data are counts
|
| 370 |
plotting_args += ["--n_col", f"{n_col}", "--data_are_counts"]
|
| 371 |
|
| 372 |
+
plotting_args += element_flags
|
| 373 |
|
| 374 |
plotting_args = " ".join(plotting_args)
|
| 375 |
|
design.py
CHANGED
|
@@ -53,25 +53,49 @@ def design_section(
|
|
| 53 |
col1, col2, col3 = st.columns(3)
|
| 54 |
with col1:
|
| 55 |
output["width"] = st.number_input(
|
| 56 |
-
"Width (px)", value=1200 + 100 * (num_classes - 2)
|
| 57 |
)
|
| 58 |
with col2:
|
| 59 |
output["height"] = st.number_input(
|
| 60 |
-
"Height (px)", value=1200 + 100 * (num_classes - 2)
|
| 61 |
)
|
| 62 |
with col3:
|
| 63 |
-
output["dpi"] = st.number_input("DPI (not working)", value=320)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
with st.expander("Elements"):
|
| 66 |
-
col1, col2
|
| 67 |
with col1:
|
| 68 |
-
output["
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
with col2:
|
| 70 |
-
output["
|
| 71 |
-
"
|
| 72 |
)
|
| 73 |
-
with col3:
|
| 74 |
-
output["show_sums"] = st.checkbox("Show sum tiles", value=False)
|
| 75 |
|
| 76 |
st.markdown("""---""")
|
| 77 |
|
|
@@ -85,6 +109,9 @@ def design_section(
|
|
| 85 |
"Show column percentages", value=num_classes < 6
|
| 86 |
)
|
| 87 |
output["show_arrows"] = st.checkbox("Show arrows", value=True)
|
|
|
|
|
|
|
|
|
|
| 88 |
with col2:
|
| 89 |
output["arrow_size"] = (
|
| 90 |
st.slider(
|
|
@@ -107,21 +134,6 @@ def design_section(
|
|
| 107 |
/ 10
|
| 108 |
)
|
| 109 |
|
| 110 |
-
st.markdown("""---""")
|
| 111 |
-
|
| 112 |
-
col1, col2, col3 = st.columns(3)
|
| 113 |
-
with col1:
|
| 114 |
-
output["counts_on_top"] = st.checkbox(
|
| 115 |
-
"Counts on top (not working)",
|
| 116 |
-
help="Whether to switch the positions of the counts and normalized counts (%). "
|
| 117 |
-
"That is, the counts become the big centralized numbers and the "
|
| 118 |
-
"normalized counts go below with a smaller font size.",
|
| 119 |
-
)
|
| 120 |
-
with col2:
|
| 121 |
-
output["diag_percentages_only"] = st.checkbox(
|
| 122 |
-
"Diagonal row/column percentages only"
|
| 123 |
-
)
|
| 124 |
-
|
| 125 |
with st.expander("Tiles"):
|
| 126 |
col1, col2, col3 = st.columns(3)
|
| 127 |
with col1:
|
|
@@ -172,6 +184,36 @@ def design_section(
|
|
| 172 |
],
|
| 173 |
)
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
with st.expander("Zero Counts"):
|
| 176 |
st.write("Special settings for tiles where the count is 0:")
|
| 177 |
col1, col2, col3 = st.columns(3)
|
|
@@ -190,27 +232,15 @@ def design_section(
|
|
| 190 |
help="Only relevant when row/column percentages are enabled.",
|
| 191 |
)
|
| 192 |
|
| 193 |
-
with st.expander("Text"):
|
| 194 |
-
col1, col2, col3 = st.columns(3)
|
| 195 |
-
with col1:
|
| 196 |
-
output["num_digits"] = st.number_input(
|
| 197 |
-
"Digits", value=2, help="Number of digits to round percentages to."
|
| 198 |
-
)
|
| 199 |
-
with col2:
|
| 200 |
-
output["rotate_y_text"] = st.checkbox("Rotate y text", value=True)
|
| 201 |
-
with col3:
|
| 202 |
-
output["place_x_axis_above"] = st.checkbox(
|
| 203 |
-
"Place X axis on top", value=True
|
| 204 |
-
)
|
| 205 |
-
|
| 206 |
with st.expander("Fonts"):
|
| 207 |
font_dicts = {}
|
| 208 |
-
|
| 209 |
"Counts",
|
| 210 |
"Normalized (%)",
|
| 211 |
"Row Percentage",
|
| 212 |
"Column Percentage",
|
| 213 |
-
]
|
|
|
|
| 214 |
st.subheader(font_type)
|
| 215 |
num_cols = 3
|
| 216 |
font_dicts[font_type] = font_inputs(key_prefix=font_type)
|
|
@@ -220,11 +250,25 @@ def design_section(
|
|
| 220 |
with cols[i % num_cols]:
|
| 221 |
setting_widget()
|
| 222 |
|
| 223 |
-
|
|
|
|
|
|
|
|
|
|
| 224 |
|
| 225 |
if st.form_submit_button(label="Generate plot"):
|
| 226 |
st.session_state["step"] = 3
|
| 227 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
return output
|
| 229 |
|
| 230 |
|
|
|
|
| 53 |
col1, col2, col3 = st.columns(3)
|
| 54 |
with col1:
|
| 55 |
output["width"] = st.number_input(
|
| 56 |
+
"Width (px)", value=1200 + 100 * (num_classes - 2), step=50
|
| 57 |
)
|
| 58 |
with col2:
|
| 59 |
output["height"] = st.number_input(
|
| 60 |
+
"Height (px)", value=1200 + 100 * (num_classes - 2), step=50
|
| 61 |
)
|
| 62 |
with col3:
|
| 63 |
+
output["dpi"] = st.number_input("DPI (not working)", value=320, step=10)
|
| 64 |
+
|
| 65 |
+
st.write(" ") # Slightly bigger gap between the two sections
|
| 66 |
+
col1, col2, col3 = st.columns(3)
|
| 67 |
+
with col1:
|
| 68 |
+
output["show_counts"] = st.checkbox("Show Counts", value=True)
|
| 69 |
+
with col2:
|
| 70 |
+
output["show_normalized"] = st.checkbox("Show Normalized (%)", value=True)
|
| 71 |
+
with col3:
|
| 72 |
+
output["show_sums"] = st.checkbox(
|
| 73 |
+
"Show Sum Tiles",
|
| 74 |
+
value=False,
|
| 75 |
+
help="Show extra row and column with the "
|
| 76 |
+
"totals for that row/column.",
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
st.markdown("""---""")
|
| 80 |
+
st.markdown("**Advanced**:")
|
| 81 |
|
| 82 |
with st.expander("Elements"):
|
| 83 |
+
col1, col2 = st.columns(2)
|
| 84 |
with col1:
|
| 85 |
+
output["rotate_y_text"] = st.checkbox("Rotate y-axis text", value=True)
|
| 86 |
+
output["place_x_axis_above"] = st.checkbox(
|
| 87 |
+
"Place x-axis on top", value=True
|
| 88 |
+
)
|
| 89 |
+
output["counts_on_top"] = st.checkbox(
|
| 90 |
+
"Counts on top (not working)",
|
| 91 |
+
help="Whether to switch the positions of the counts and normalized counts (%). "
|
| 92 |
+
"The counts become the big centralized numbers and the "
|
| 93 |
+
"normalized counts go below with a smaller font size.",
|
| 94 |
+
)
|
| 95 |
with col2:
|
| 96 |
+
output["num_digits"] = st.number_input(
|
| 97 |
+
"Digits", value=2, help="Number of digits to round percentages to."
|
| 98 |
)
|
|
|
|
|
|
|
| 99 |
|
| 100 |
st.markdown("""---""")
|
| 101 |
|
|
|
|
| 109 |
"Show column percentages", value=num_classes < 6
|
| 110 |
)
|
| 111 |
output["show_arrows"] = st.checkbox("Show arrows", value=True)
|
| 112 |
+
output["diag_percentages_only"] = st.checkbox(
|
| 113 |
+
"Diagonal row/column percentages only"
|
| 114 |
+
)
|
| 115 |
with col2:
|
| 116 |
output["arrow_size"] = (
|
| 117 |
st.slider(
|
|
|
|
| 134 |
/ 10
|
| 135 |
)
|
| 136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
with st.expander("Tiles"):
|
| 138 |
col1, col2, col3 = st.columns(3)
|
| 139 |
with col1:
|
|
|
|
| 184 |
],
|
| 185 |
)
|
| 186 |
|
| 187 |
+
st.markdown("""---""")
|
| 188 |
+
|
| 189 |
+
st.write("Sum tile settings:")
|
| 190 |
+
|
| 191 |
+
col1, col2 = st.columns(2)
|
| 192 |
+
with col1:
|
| 193 |
+
output["sum_tile_palette"] = st.selectbox(
|
| 194 |
+
"Color Palette",
|
| 195 |
+
key="sum_tiles_color_palette",
|
| 196 |
+
options=["Greens", "Oranges", "Greys", "Purples", "Reds", "Blues"],
|
| 197 |
+
)
|
| 198 |
+
with col2:
|
| 199 |
+
output["sum_tile_label"] = st.text_input(
|
| 200 |
+
"Label",
|
| 201 |
+
value="Σ",
|
| 202 |
+
key="sum_tiles_label",
|
| 203 |
+
)
|
| 204 |
+
|
| 205 |
+
# label = NULL,
|
| 206 |
+
# tile_fill = NULL,
|
| 207 |
+
# font_color = NULL,
|
| 208 |
+
# tile_border_color = NULL,
|
| 209 |
+
# tile_border_size = NULL,
|
| 210 |
+
# tile_border_linetype = NULL,
|
| 211 |
+
# tc_tile_fill = NULL,
|
| 212 |
+
# tc_font_color = NULL,
|
| 213 |
+
# tc_tile_border_color = NULL,
|
| 214 |
+
# tc_tile_border_size = NULL,
|
| 215 |
+
# tc_tile_border_linetype = NULL
|
| 216 |
+
|
| 217 |
with st.expander("Zero Counts"):
|
| 218 |
st.write("Special settings for tiles where the count is 0:")
|
| 219 |
col1, col2, col3 = st.columns(3)
|
|
|
|
| 232 |
help="Only relevant when row/column percentages are enabled.",
|
| 233 |
)
|
| 234 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
with st.expander("Fonts"):
|
| 236 |
font_dicts = {}
|
| 237 |
+
font_types = [
|
| 238 |
"Counts",
|
| 239 |
"Normalized (%)",
|
| 240 |
"Row Percentage",
|
| 241 |
"Column Percentage",
|
| 242 |
+
]
|
| 243 |
+
for font_type in font_types:
|
| 244 |
st.subheader(font_type)
|
| 245 |
num_cols = 3
|
| 246 |
font_dicts[font_type] = font_inputs(key_prefix=font_type)
|
|
|
|
| 250 |
with cols[i % num_cols]:
|
| 251 |
setting_widget()
|
| 252 |
|
| 253 |
+
if font_type != font_types[-1]:
|
| 254 |
+
st.markdown("""---""")
|
| 255 |
+
|
| 256 |
+
st.markdown("""---""")
|
| 257 |
|
| 258 |
if st.form_submit_button(label="Generate plot"):
|
| 259 |
st.session_state["step"] = 3
|
| 260 |
|
| 261 |
+
if st.session_state["step"] >= 3:
|
| 262 |
+
output["design_ready"] = True
|
| 263 |
+
if output["show_sums"] and output["sum_tile_palette"] == output["palette"]:
|
| 264 |
+
st.error(
|
| 265 |
+
"The color palettes (background colors) "
|
| 266 |
+
"for the tiles and sum tiles are identical. "
|
| 267 |
+
"Please select a different color palette for "
|
| 268 |
+
"the sum tiles under **Tiles** >> *Sum tile settings*."
|
| 269 |
+
)
|
| 270 |
+
output["design_ready"] = False
|
| 271 |
+
|
| 272 |
return output
|
| 273 |
|
| 274 |
|
text_sections.py
CHANGED
|
@@ -127,3 +127,8 @@ def columns_text():
|
|
| 127 |
def design_text():
|
| 128 |
st.subheader("Design your plot")
|
| 129 |
st.write("This is where you customize the design of your confusion matrix plot.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
def design_text():
|
| 128 |
st.subheader("Design your plot")
|
| 129 |
st.write("This is where you customize the design of your confusion matrix plot.")
|
| 130 |
+
st.write(
|
| 131 |
+
"The width and height settings are usually necessary to adjust as they "
|
| 132 |
+
"change the relative size of the elements. Try adjusting 100px at a "
|
| 133 |
+
"time for a start."
|
| 134 |
+
)
|