Overlapping legend and barchart

Hi,

It´s already the third time that i find myself having problems with matplotlib legends. In fact, when there is not enough space to fit it, matplotlib´s choice is just to cover part of the graph with the legend. I know that there are some solutions that solve the problem with some “tricks” (e.g. putting the legend as a new axis or using the bbox_to_anchor), but I´m wondering if there is instead any way to adjust it “dynamically” in the graph. What I mean is a way in which the legend is automatically resized so that it fits in the space (so that, if one wants the legend to be in the graph, they don´t have to do it manually every time). Does anyone know about the existence of something like what I´m describing?
To give you an example of what I mean, here is some very simple code in which it happens with attached the output:
from matplotlib import pyplot as plt

list_ = [“a”, “b”, “c”, “d”]

numbers = [5, 4, 3, 4]

fig, ax = plt.subplots()

bars = ax.bar(list_, numbers, label=“Bar Group”)

ax.legend([bars[i] for i in range(len(list_))], list_)

plt.show()

thank you very much for your help!
P.S. this is my first post here, so if you also have advice on how to better ask questions feel free!