Place a centered label inside a bar segment if it's tall enough.
(ax, rect, text: str, min_height: float = 0.3)
| 185 | |
| 186 | |
| 187 | def _label_bar(ax, rect, text: str, min_height: float = 0.3) -> None: |
| 188 | """Place a centered label inside a bar segment if it's tall enough.""" |
| 189 | h = rect.get_height() |
| 190 | if h < min_height: |
| 191 | return |
| 192 | ax.text( |
| 193 | rect.get_x() + rect.get_width() / 2, |
| 194 | rect.get_y() + h / 2, |
| 195 | text, |
| 196 | ha="center", |
| 197 | va="center", |
| 198 | fontsize=10, |
| 199 | color="white", |
| 200 | fontweight="bold", |
| 201 | ) |
| 202 | |
| 203 | |
| 204 | if __name__ == "__main__": |