Skip to content
Snippets Groups Projects
Commit d5b1fdff authored by Hock, Martin's avatar Hock, Martin
Browse files

Merge branch '80-create-option-to-only-add-id-to-metadata-and-do-not-on-figure-picture' into 'dev'

Allow to not print the ID on to the plot by passing id_on_plot=False to tagplot().

See merge request !45
parents 914b8f5b 6f716786
No related branches found
No related tags found
2 merge requests!52Create v0.2.2,!45Allow to not print the ID on to the plot by passing id_on_plot=False to tagplot().
Pipeline #855254 waiting for manual action
...@@ -64,6 +64,8 @@ Optional parameters can be used to customize the tag process. ...@@ -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'. Location for ID to be displayed on the plot. Default is 'east'.
- *qrcode* : boolean, optional - *qrcode* : boolean, optional
Experimental support for encoding the ID in a QR Code. Experimental support for encoding the ID in a QR Code.
- *id_on_plot* : boolean, optional
Print ID on the plot. Default: True.
Example: Example:
```python ```python
......
...@@ -40,6 +40,8 @@ class PlotOptions: ...@@ -40,6 +40,8 @@ class PlotOptions:
The default is 'time'. The default is 'time'.
qrcode : bool, optional qrcode : bool, optional
Experimental status. Print qrcode on exported plot. Default: False. 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): def __init__(self, figs, rotation, position, **kwargs):
...@@ -51,6 +53,7 @@ class PlotOptions: ...@@ -51,6 +53,7 @@ class PlotOptions:
self.prefix = kwargs.get("prefix", "") self.prefix = kwargs.get("prefix", "")
self.id_method = kwargs.get("id_method", "time") self.id_method = kwargs.get("id_method", "time")
self.qrcode = kwargs.get("qrcode", False) self.qrcode = kwargs.get("qrcode", False)
self.id_on_plot = kwargs.get("id_on_plot", True)
def __str__(self): def __str__(self):
"""Representation if an object of this class is printed.""" """Representation if an object of this class is printed."""
......
...@@ -48,6 +48,7 @@ def tagplot_image(plotid_object): ...@@ -48,6 +48,7 @@ def tagplot_image(plotid_object):
plotid_object.figure_ids.append(img_id) plotid_object.figure_ids.append(img_id)
img = Image.open(img) img = Image.open(img)
if plotid_object.id_on_plot:
img_txt = Image.new("L", font.getsize(img_id)) img_txt = Image.new("L", font.getsize(img_id))
draw_txt = ImageDraw.Draw(img_txt) draw_txt = ImageDraw.Draw(img_txt)
draw_txt.text((0, 0), img_id, font=font, fill=255) draw_txt.text((0, 0), img_id, font=font, fill=255)
......
...@@ -47,8 +47,9 @@ def tagplot_matplotlib(plotid_object): ...@@ -47,8 +47,9 @@ def tagplot_matplotlib(plotid_object):
fig_id = create_id(plotid_object.id_method) fig_id = create_id(plotid_object.id_method)
fig_id = plotid_object.prefix + fig_id fig_id = plotid_object.prefix + fig_id
plotid_object.figure_ids.append(fig_id) plotid_object.figure_ids.append(fig_id)
plt.figure(fig) plt.figure(fig)
if plotid_object.id_on_plot:
plt.figtext( plt.figtext(
x=plotid_object.position[0], x=plotid_object.position[0],
y=plotid_object.position[1], y=plotid_object.position[1],
......
...@@ -39,14 +39,19 @@ class TestTagplot(unittest.TestCase): ...@@ -39,14 +39,19 @@ class TestTagplot(unittest.TestCase):
Test if the string representation of a PlotOptions object is correct. Test if the string representation of a PlotOptions object is correct.
""" """
plot_obj = PlotOptions( 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( self.assertEqual(
str(plot_obj), str(plot_obj),
"<class 'plotid.plotoptions.PlotOptions'>: {'figs': " "<class 'plotid.plotoptions.PlotOptions'>: {'figs': "
"'FIG', 'figure_ids': [], 'rotation': 270, 'position'" "'FIG', 'figure_ids': [], 'rotation': 270, 'position'"
": (100, 200), 'prefix': 'xyz', 'id_method': " ": (100, 200), 'prefix': 'xyz', 'id_method': "
"'random', 'qrcode': False}", "'random', 'qrcode': False, 'id_on_plot': False}",
) )
def test_str_plotidtransfer(self): def test_str_plotidtransfer(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment