I am writing a library on top of matplotlib to extract data in a specific format. For example, in bar plot, I need the data, title, axes lables, etc in a particular structure. Right now, I have a written the package to extract the features based on the given input’s axes.
import matplotlib.pyplot as plt
import maidr # custom package
bar_plot = plt.bar(# bar plot code)
# extract features based on the current axes state of bar_plot. For example,
# ax = bar_plot.get_children()[0].axes
# bar_maidr.title = ax.get_title()
bar_maidr = maidr.bar(bar_plot)
If the plots are to be modified later, I need to update my extracted features accordingly. I looked around and found callbacks could be added for each Artist. However, not all changes trigger those callbacks.
bar_plot = plt.bar(# bar plot code)
plt.title("First Title")
bar_maidr = maidr.bar(bar_plot) # bar_maidr.title will still be "First Title"
# I need to add callback on the axes's title property, which upon changing will trigger my callback. For example,
#
# bar_maidr.on_title_change(new_title):
# self.title = new_title
# title.add_callback(on_title_change)
#
# The below line should update my bar_maidr.title from "First Title" to "Second Title", but there is no trigger happening
plt.title("Second Title")
Is it possible to trigger callbacks based on Artist’s property change?