[yoda-svn] yoda: Add some protection against calling matplotlib's legend() ...

YODA Mercurial yoda at projects.hepforge.org
Mon Aug 17 00:45:01 BST 2015


details:   https://yoda.hepforge.org/hg/yoda/rev/34a36aa3478e
branches:  
changeset: 1111:34a36aa3478e
user:      Andy Buckley <andy at insectnation.org>
date:      Mon Aug 17 00:37:22 2015 +0100
description:
Add some protection against calling matplotlib's legend() method if there are no valid labels to display, to suppress an MPL warning message when using yoda.plot().

diffs (35 lines):

--- a/ChangeLog	Wed Aug 12 22:55:43 2015 +0100
+++ b/ChangeLog	Mon Aug 17 00:37:22 2015 +0100
@@ -1,3 +1,9 @@
+2015-08-17  Andy Buckley  <andy.buckley at cern.ch>
+
+	* Add some protection against calling matplotlib's legend() method
+	if there are no valid labels to display, to suppress an MPL
+	warning message when using yoda.plot().
+
 2015-08-12  Andy Buckley  <andy.buckley at cern.ch>
 
 	* Fix cut & paste typo, and add LowStatsError catching in Profile division.
--- a/pyext/yoda/plotting.py	Wed Aug 12 22:55:43 2015 +0100
+++ b/pyext/yoda/plotting.py	Mon Aug 17 00:37:22 2015 +0100
@@ -440,13 +440,18 @@
         axratio.axhline(1.0, color="gray")
 
     ## Dataset plotting
+    some_valid_label = False
     for ih, h in enumerate(hs):
         #print ih, h.path
-        plot_hist_on_axes_1d(axmain, axratio, h, href)
+        aa = plot_hist_on_axes_1d(axmain, axratio, h, href)
+        if aa and not aa[0].get_label().startswith("_"):
+            # print "@@@", aa[0].get_label()
+            some_valid_label = True
 
     ## Legend
     # TODO: allow excluding and specify order via LegendIndex
-    axmain.legend(loc=plotkeys.get("LegendPos", "best"), fontsize=plotkeys.get("LegendFontSize", "x-small"), frameon=False)
+    if some_valid_label: #< No point in writing a legend if there are no labels
+        pass #axmain.legend(loc=plotkeys.get("LegendPos", "best"), fontsize=plotkeys.get("LegendFontSize", "x-small"), frameon=False)
 
     ## Tweak layout now that everything is in place
     # TODO: merge tight_layout() into the Figure constructor, and maybe the ratio ticker when retrospectively drawing the zorder'ed err band


More information about the yoda-svn mailing list