print_codeο
- AnnotationEditor.print_code(m_name='m', what='all', sanitize_coordinates=True, replace=None, use_ids=False)ο
Print the code to reproduce the annotations to the console.
Note
While this works nicely in most standard cases, it can not be guaranteed that extensively customized annotations are properly translated to code!
Text-functions that are used to dynamically update the annotation-text will be replaced by the currently visible text! To maintain interactivity, you can replace individual arguments via the replace dict.
If coordinates are provided in a custom crs, they will be reprojected to epsg=4326 to avoid issues with incorrect string-representations of the crs and to make the annotation independent of the current map-crs (in case xy_crs=None).
- Parameters:
m_name (str, optional) β The variable-name of the Maps-object used in the code. (code will be generated as < m_name >.add_annotation(β¦)) The default is βmβ.
what (str, int or list of int, optional) β
Indicator which annotation codes should be printed.
if βallβ: the code for all annotations is printed
if int: only the code for the nth annotation is printed
if list of int: the code for the annotations [0,.., i, .., n] is printed
The default is βallβ.
sanitize_coordinates (bool, optional) β
If Tue, annotation coordinates where the crs has not been specified explicitly are reprojected to epsg=4326 to avoid amiguities (e.g. if the plot-crs changes etc.)
If False, coordinates will be returned as-is (which might lead to incorrect results in some cases). The default is True
replace (dict or None, optional) β
A dictionary of values used to replace the arguments of the annotation-call. This is particularly useful if you want to keep annotations interactive, for example if you use a function to set the text, you can use the following to maintain the function in the printed text:
>>> my_textfunc = lambda ID, **kwargs: str(ID) >>> m._edit_annotations.print_code(replace={"text": my_textfunc})
use_ids (bool, optional) β
If True, ID values are used to identify the annotation-positions. (NOTE: this can cause problems because the Maps-object must have
the correct data assigned to identify the annotation!)
If False, always use the current position of the annotation as input-argument for the returned code.