add_annotationο
- MapsGrid.add_annotation(ID=None, xy=None, xy_crs=None, text=None, update=True, **kwargs)ο
This will execute the corresponding action on ALL Maps objects of the MapsGrid!
Add an annotation to the plot.
- Parameters:
ID (str, int, float or array-like) β The index-value of the pixel in m.data.
xy (tuple of float or array-like) β A tuple of the position of the pixel provided in βxy_crsβ. If None, xy must be provided in the coordinate-system of the plot! The default is None.
xy_crs (any) β the identifier of the coordinate-system for the xy-coordinates
text (callable or str, optional) β
if str: the string to print if callable: A function that returns the string that should be printed in the annotation with the following call-signature:
>>> def text(m, ID, val, pos, ind): >>> # m ... the Maps object >>> # ID ... the ID >>> # pos ... the position >>> # val ... the value >>> # ind ... the index of the clicked pixel >>> >>> return "the string to print"
The default is None.
update (bool, optional) β If True, call m.BM.update() to immediately show dynamic annotations If False, dynamic annotations will only be shown at the next update
**kwargs β kwargs passed to m.cb.annotate
Examples
>>> m.add_annotation(ID=1) >>> m.add_annotation(xy=(45, 35), xy_crs=4326)
NOTE: You can provide lists to add multiple annotations in one go!
>>> m.add_annotation(ID=[1, 5, 10, 20]) >>> m.add_annotation(xy=([23.5, 45.8, 23.7], [5, 6, 7]), xy_crs=4326)
The text can be customized by providing either a string
>>> m.add_annotation(ID=1, text="some text")
or a callable that returns a string with the following signature:
>>> def addtxt(m, ID, val, pos, ind): >>> return f"The ID {ID} at position {pos} has a value of {val}" >>> m.add_annotation(ID=1, text=addtxt)
Customizing the appearance
For the full set of possibilities, see: https://matplotlib.org/stable/tutorials/text/annotations.html
>>> m.add_annotation(xy=[7.10, 45.16], xy_crs=4326, >>> text="blubb", xytext=(30,30), >>> horizontalalignment="center", verticalalignment="center", >>> arrowprops=dict(ec="g", >>> arrowstyle='-[', >>> connectionstyle="angle", >>> ), >>> bbox=dict(boxstyle='circle,pad=0.5', >>> fc='yellow', >>> alpha=0.3 >>> ) >>> )