[GRASS-SVN] r68606 - grass-addons/grass7/raster/r.colors.matplotlib

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jun 4 13:37:23 PDT 2016


Author: wenzeslaus
Date: 2016-06-04 13:37:23 -0700 (Sat, 04 Jun 2016)
New Revision: 68606

Modified:
   grass-addons/grass7/raster/r.colors.matplotlib/r.colors.matplotlib.py
Log:
r.colors.matplotlib: check for existence of color table

This is important because of different versions of mpl
and also because the traceback has some message related
to some RGB color definition (probably hitting some fallback).


Modified: grass-addons/grass7/raster/r.colors.matplotlib/r.colors.matplotlib.py
===================================================================
--- grass-addons/grass7/raster/r.colors.matplotlib/r.colors.matplotlib.py	2016-06-04 20:33:20 UTC (rev 68605)
+++ grass-addons/grass7/raster/r.colors.matplotlib/r.colors.matplotlib.py	2016-06-04 20:37:23 UTC (rev 68606)
@@ -85,7 +85,7 @@
 import os
 import sys
 import grass.script as gscript
-import matplotlib.pyplot as plt
+import matplotlib.cm as cm
 
 
 def values_to_rule(value, red, green, blue, percent):
@@ -139,8 +139,17 @@
     if flags['n']:
         name += '_r'
 
-    cmap = plt.get_cmap(name, lut=n_colors)
+    # not sure if datad is part of the API but it is in one example
+    # datad might be potentially better way of getting the table
+    # it contains the raw data, but on the other hand it might not be
+    # clear if you can interpolate linearly in between (but likely yes)
+    if hasattr(cm, 'datad') and name not in cm.datad.keys():
+        import matplotlib as mpl
+        gscript.fatal(_("Matplotlib {v} does not contain color table"
+                        " <{n}>").format(v=mpl.__version__, n=name))
 
+    cmap = cm.get_cmap(name, lut=n_colors)
+
     comments = []
     comments.append(
         "Generated from Matplotlib color table <{}>".format(name))



More information about the grass-commit mailing list