{"id":90,"date":"2015-08-28T15:23:58","date_gmt":"2015-08-28T13:23:58","guid":{"rendered":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/?p=90"},"modified":"2015-10-12T14:03:48","modified_gmt":"2015-10-12T12:03:48","slug":"generating-automatic-figure-labels","status":"publish","type":"post","link":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/2015\/08\/28\/generating-automatic-figure-labels\/","title":{"rendered":"Generating automatic figure labels"},"content":{"rendered":"<p><strong>Following the German motto <em>&#8220;Ordnung ist das halbe Leben!&#8221;<\/em><\/strong><\/p>\n<p>Have you ever been frustrated by having to differentiate between dozens of similar graphs or figures, and the only memorable difference between them were their unique file names?<\/p>\n<p>In a recent simulation study, I had exactly that feeling, so I came up with some code to automatically label figures with their file names. Here is how it works:<\/p>\n<p>For example, please assume three similar graphs with the file names <em>testResults_A.png<\/em>, <em>testResults_B.png<\/em>, and <em>testResults_C.png<\/em>, respectively.<\/p>\n<div id=\"attachment_91\" style=\"width: 160px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_A.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-91\" class=\"size-thumbnail wp-image-91\" src=\"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_A-150x150.png\" alt=\"testResults_A\" width=\"150\" height=\"150\" srcset=\"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_A-150x150.png 150w, https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_A-300x300.png 300w, https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_A.png 630w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/a><p id=\"caption-attachment-91\" class=\"wp-caption-text\">testResults_A<\/p><\/div>\n<div id=\"attachment_92\" style=\"width: 160px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_B.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-92\" class=\"size-thumbnail wp-image-92\" src=\"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_B-150x150.png\" alt=\"testResults_B\" width=\"150\" height=\"150\" srcset=\"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_B-150x150.png 150w, https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_B-300x300.png 300w, https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_B.png 630w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/a><p id=\"caption-attachment-92\" class=\"wp-caption-text\">testResults_B<\/p><\/div>\n<div id=\"attachment_93\" style=\"width: 160px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_C.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-93\" class=\"size-thumbnail wp-image-93\" src=\"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_C-150x150.png\" alt=\"testResults_C\" width=\"150\" height=\"150\" srcset=\"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_C-150x150.png 150w, https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_C-300x300.png 300w, https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_C.png 630w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/a><p id=\"caption-attachment-93\" class=\"wp-caption-text\">testResults_C<\/p><\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Let us annotate each figure automatically with its file name (but excluding the file type ending) using <a href=\"https:\/\/www.imagemagick.org\/script\/index.php\" target=\"_blank\">ImageMagick<\/a>.<\/p>\n<div style=\"background-color: #ffebdb\">\n<p style=\"padding-left: 30px\"><code>for i in $(ls *.png); do convert $i -background Orange label:${i%.png*} +swap -gravity Center -append ${i%.png*}.withAnno.png; done<\/code><\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p>On the top of each figure, an orange bar with the respective file name has now been added.<\/p>\n<div id=\"attachment_101\" style=\"width: 160px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_A.withAnno.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-101\" class=\"size-thumbnail wp-image-101\" src=\"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_A.withAnno-150x150.png\" alt=\"annotated testResults_A\" width=\"150\" height=\"150\" \/><\/a><p id=\"caption-attachment-101\" class=\"wp-caption-text\">annotated testResults_A<\/p><\/div>\n<div id=\"attachment_102\" style=\"width: 160px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_B.withAnno.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-102\" class=\"size-thumbnail wp-image-102\" src=\"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_B.withAnno-150x150.png\" alt=\"annotated testResults_B\" width=\"150\" height=\"150\" \/><\/a><p id=\"caption-attachment-102\" class=\"wp-caption-text\">annotated testResults_B<\/p><\/div>\n<div id=\"attachment_103\" style=\"width: 160px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_C.withAnno.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-103\" class=\"size-thumbnail wp-image-103\" src=\"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/files\/2015\/08\/testResults_C.withAnno-150x150.png\" alt=\"annotated testResults_C\" width=\"150\" height=\"150\" \/><\/a><p id=\"caption-attachment-103\" class=\"wp-caption-text\">annotated testResults_C<\/p><\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>UPDATE: I found it necessary to manually set the font size in several cases. It is hereby important to set option <em>pointsize<\/em> as the first option in the list.<\/p>\n<div style=\"background-color: #ffebdb\">\n<p style=\"padding-left: 30px\"><code>for i in $(ls *.png); do convert $i <strong>-pointsize 60<\/strong> -background Orange label:${i%.png*} +swap -gravity Center -append ${i%.png*}.withAnno.png; done<\/code><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Following the German motto &#8220;Ordnung ist das halbe Leben!&#8221; Have you ever been frustrated by having to differentiate between dozens of similar graphs or figures, and the only memorable difference between them were their unique file names? In a recent simulation study, I had exactly that feeling, so I came up with some code to [&hellip;]<\/p>\n","protected":false},"author":2306,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[57599,57598],"tags":[],"class_list":["post-90","post","type-post","status-publish","format-standard","hentry","category-audiovisual","category-bioinformatics"],"_links":{"self":[{"href":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/wp-json\/wp\/v2\/posts\/90","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/wp-json\/wp\/v2\/users\/2306"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/wp-json\/wp\/v2\/comments?post=90"}],"version-history":[{"count":17,"href":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/wp-json\/wp\/v2\/posts\/90\/revisions"}],"predecessor-version":[{"id":108,"href":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/wp-json\/wp\/v2\/posts\/90\/revisions\/108"}],"wp:attachment":[{"href":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/wp-json\/wp\/v2\/media?parent=90"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/wp-json\/wp\/v2\/categories?post=90"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/wp-json\/wp\/v2\/tags?post=90"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}