| 2415 | |
| 2416 | |
| 2417 | def plot_label_within_limits(self, ax, x, y, text, fontsize=8): # Plots the labels inside the plot area |
| 2418 | x_min, x_max = ax.get_xlim() # Get x-limits |
| 2419 | y_min, y_max = ax.get_ylim() # Get y-limits |
| 2420 | |
| 2421 | # Calculate the buffer as 5% of the y-axis range (which represents depth or the vertical dimension in the plot) |
| 2422 | buffer_y = 0.025 * (y_max - y_min) |
| 2423 | |
| 2424 | # Adjust the y-coordinate for the label to be slightly below |
| 2425 | label_y = y - buffer_y |
| 2426 | if label_y < y_min: |
| 2427 | label_y = y_min |
| 2428 | |
| 2429 | # horizontal alignment based on the hole's orientation |
| 2430 | if x > (x_max + x_min) / 2: # If the hole is on the right half of the plot |
| 2431 | ha = "right" |
| 2432 | else: |
| 2433 | ha = "left" |
| 2434 | |
| 2435 | # Plot the label |
| 2436 | ax.text(x, label_y, text, fontsize=fontsize, zorder=6, ha=ha) |
| 2437 | |
| 2438 | |
| 2439 | |