diff --git a/README.md b/README.md index 899d1357177c8d4157a7027ba764f0babe6967fb..cb3c6d0355c732afba08a01f5d9e0a99d70cff08 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,8 @@ Optional parameters can be used to customize the tag process. Location for ID to be displayed on the plot. Default is 'east'. - *qrcode* : boolean, optional Experimental support for encoding the ID in a QR Code. +- *id_on_plot* : boolean, optional + Print ID on the plot. Default: True. Example: ```python diff --git a/plotid/plotoptions.py b/plotid/plotoptions.py index 79f576a9e4603cc056dee355bccfeb3d34d5f847..eebdcc40541cf2de3500b9108457ba8e7e5a428c 100644 --- a/plotid/plotoptions.py +++ b/plotid/plotoptions.py @@ -40,6 +40,8 @@ class PlotOptions: The default is 'time'. qrcode : bool, optional Experimental status. Print qrcode on exported plot. Default: False. + id_on_plot: bool, optional + Print ID on the plot. Default: True. """ def __init__(self, figs, rotation, position, **kwargs): @@ -51,6 +53,7 @@ class PlotOptions: self.prefix = kwargs.get("prefix", "") self.id_method = kwargs.get("id_method", "time") self.qrcode = kwargs.get("qrcode", False) + self.id_on_plot = kwargs.get("id_on_plot", True) def __str__(self): """Representation if an object of this class is printed.""" diff --git a/plotid/tagplot_image.py b/plotid/tagplot_image.py index 7c0c6adda887cfad33e8a70423512119ee5d0f28..ccb65a24a92aa86e12b3105777bfa3abd22ead6a 100644 --- a/plotid/tagplot_image.py +++ b/plotid/tagplot_image.py @@ -48,18 +48,19 @@ def tagplot_image(plotid_object): plotid_object.figure_ids.append(img_id) img = Image.open(img) - img_txt = Image.new("L", font.getsize(img_id)) - draw_txt = ImageDraw.Draw(img_txt) - draw_txt.text((0, 0), img_id, font=font, fill=255) - txt = img_txt.rotate(plotid_object.rotation, expand=1) - img.paste( - ImageOps.colorize(txt, (0, 0, 0), color), - ( - int(img.width * plotid_object.position[0]), - int(img.height * (1 - plotid_object.position[1])), - ), - txt, - ) + if plotid_object.id_on_plot: + img_txt = Image.new("L", font.getsize(img_id)) + draw_txt = ImageDraw.Draw(img_txt) + draw_txt.text((0, 0), img_id, font=font, fill=255) + txt = img_txt.rotate(plotid_object.rotation, expand=1) + img.paste( + ImageOps.colorize(txt, (0, 0, 0), color), + ( + int(img.width * plotid_object.position[0]), + int(img.height * (1 - plotid_object.position[1])), + ), + txt, + ) if plotid_object.qrcode: qrcode = create_qrcode(img_id) diff --git a/plotid/tagplot_matplotlib.py b/plotid/tagplot_matplotlib.py index 883178ba2b3950b7e5758c2c8385bfbd820d5786..1130756b8441379eb63c4088bce9dee62b432680 100644 --- a/plotid/tagplot_matplotlib.py +++ b/plotid/tagplot_matplotlib.py @@ -47,18 +47,19 @@ def tagplot_matplotlib(plotid_object): fig_id = create_id(plotid_object.id_method) fig_id = plotid_object.prefix + fig_id plotid_object.figure_ids.append(fig_id) - plt.figure(fig) - plt.figtext( - x=plotid_object.position[0], - y=plotid_object.position[1], - s=fig_id, - ha="left", - wrap=True, - rotation=plotid_object.rotation, - fontsize=fontsize, - color=color, - ) + + if plotid_object.id_on_plot: + plt.figtext( + x=plotid_object.position[0], + y=plotid_object.position[1], + s=fig_id, + ha="left", + wrap=True, + rotation=plotid_object.rotation, + fontsize=fontsize, + color=color, + ) if plotid_object.qrcode: qrcode = create_qrcode(fig_id) diff --git a/tests/test_plotoptions.py b/tests/test_plotoptions.py index 4889c9fe98ef3eced0f6f1adeaed863095fc8f43..bd992c139cdfd34258728bf97246ce02392f8371 100644 --- a/tests/test_plotoptions.py +++ b/tests/test_plotoptions.py @@ -39,14 +39,19 @@ class TestTagplot(unittest.TestCase): Test if the string representation of a PlotOptions object is correct. """ plot_obj = PlotOptions( - "FIG", ROTATION, POSITION, prefix="xyz", id_method="random" + "FIG", + ROTATION, + POSITION, + prefix="xyz", + id_method="random", + id_on_plot=False, ) self.assertEqual( str(plot_obj), "<class 'plotid.plotoptions.PlotOptions'>: {'figs': " "'FIG', 'figure_ids': [], 'rotation': 270, 'position'" ": (100, 200), 'prefix': 'xyz', 'id_method': " - "'random', 'qrcode': False}", + "'random', 'qrcode': False, 'id_on_plot': False}", ) def test_str_plotidtransfer(self):