(
ax: Axes,
label_text: str,
x: float,
y: float,
centerx: float,
centery: float,
label_parameters: Optional[dict] = None,
)
| 128 | |
| 129 | |
| 130 | def place_label( |
| 131 | ax: Axes, |
| 132 | label_text: str, |
| 133 | x: float, |
| 134 | y: float, |
| 135 | centerx: float, |
| 136 | centery: float, |
| 137 | label_parameters: Optional[dict] = None, |
| 138 | ) -> Axes: |
| 139 | |
| 140 | if label_parameters is None: |
| 141 | label_parameters = default_label_parameters |
| 142 | else: |
| 143 | label_parameters = dict(default_label_parameters, **label_parameters) |
| 144 | |
| 145 | offset = label_parameters["offset"] |
| 146 | alpha = label_parameters["label_alpha"] |
| 147 | color = label_parameters["label_color"] |
| 148 | if "arrow_color" in label_parameters: |
| 149 | arrow_color = label_parameters["arrow_color"] |
| 150 | else: |
| 151 | arrow_color = color |
| 152 | |
| 153 | if x > centerx: |
| 154 | xtext = -offset |
| 155 | else: |
| 156 | xtext = offset |
| 157 | if y > centery: |
| 158 | ytext = -offset |
| 159 | else: |
| 160 | ytext = offset |
| 161 | |
| 162 | ax.annotate( |
| 163 | label_text, |
| 164 | xy=(x, y), |
| 165 | xytext=(xtext, ytext), |
| 166 | textcoords="offset points", |
| 167 | ha="center", |
| 168 | va="bottom", |
| 169 | bbox=dict(boxstyle="round,pad=0.2", fc=color, alpha=alpha), |
| 170 | arrowprops=dict( |
| 171 | arrowstyle="->", connectionstyle="arc3,rad=0.5", color=arrow_color |
| 172 | ), |
| 173 | ) |
| 174 | return ax |
| 175 | |
| 176 | |
| 177 | # ------------------------------------------------------- # |
no outgoing calls
no test coverage detected