It's my first time asking a question here. So please tell me if anything is amiss.
So I’m trying to create a dataset of synthetically generated charts to train a neural net to find bounding boxes for different elements of a chart - legend box, chart title, axes labels, etc. That's the part I've managed to do.
Next what I need is to create a mapping from different legend entries to their corresponding datapoints. I need to create annotations for bounding boxes around the different handles and text like this:
I've tried looking around the docs, but there can't find any related functionality. Looking into properties of legend using matplotlib.artist.getp()
also got me nothing on this.
fig, ax = plt.subplots(figsize=(12, 4))
x_vals = np.linspace(0, 5, 5)
y_vals = np.random.uniform(size=(5,))
ax.plot(x_vals, y_vals, label='line1')
ax.plot(x_vals, y_vals + np.random.randn(), label='line2')
leg = ax.legend()
ax.set_label('Label via method')
matplotlib.artist.getp(leg)
Output:
agg_filter = None
alpha = None
animated = False
bbox_to_anchor = TransformedBbox( Bbox(x0=0.125, y0=0.125, x1=0...
children = [<matplotlib.offsetbox.VPacker object at 0x7f3582d...
clip_box = None
clip_on = True
clip_path = None
contains = None
default_handler_map = {<class 'matplotlib.container.StemContainer'>: <ma...
figure = Figure(864x288)
frame = FancyBboxPatch(640.55,203.64;60.625x33)
frame_on = True
gid = None
label =
legend_handler_map = {<class 'matplotlib.container.StemContainer'>: <ma...
lines = [<matplotlib.lines.Line2D object at 0x7f35834f4400...
patches = <a list of 0 Patch objects>
path_effects = []
picker = None
rasterized = None
sketch_params = None
snap = None
texts = <a list of 2 Text objects>
title = Text(0,0,'None')
transform = IdentityTransform()
transformed_clip_path_and_affine = (None, None)
url = None
visible = True
window_extent = Bbox(x0=640.5500000000001, y0=203.64, x1=701.17500...
zorder = 5
Any help would be appreciated. Please tell me if any clarification is needed. Thanks