Commits

Anonymous committed 5fe6ba6

Remove direct dependency to matplotlib from plugin code. Hopefully will fix matplotlib backend problem.

  • Participants
  • Parent commits 95c157a

Comments (0)

Files changed (5)

docs/ref/index.rst

 .. toctree::
 
     application
-    network
-    task
-    file
     db
     event
+    file
+    loading
+    network
+    plugin
     plot
-    loading
+    task
     util
-    plugin
     contrib/index
     

docs/ref/network.rst

-===============================
-:mod:`hornet.network` -- hornet
-===============================
+=============================================================
+:mod:`hornet.network` -- Graph Representations & Interactions
+=============================================================
 
 .. testsetup:: *
 

docs/ref/plot.rst

-==============================
-:mod:`hornet.plot` -- Plotting
-==============================
+======================================
+:mod:`hornet.plot` -- Graphing Library
+======================================
 
 .. testsetup:: *
 

src/hornet/contrib/rulethreshold.py

 from hornet.plugin import Plugin, log
 from hornet.util import accumulate
 import hornet.network
+import hornet.plot as plot
 import logging
 import operator
-import pylab
 
 logger = logging.getLogger(__name__)
 
             
             result = accumulate(pdf)
             self.results[graph.meta.period] = result    
-            pylab.plot(result.keys(), result.values(), '.')
-            pylab.show()
+            plot.xyscatter(result.keys(), result.values(), fmt='.')
+            plot.show()
             #FIXME premature end
             break
     

src/hornet/plot.py

 import matplotlib; matplotlib.use('Agg')
 import matplotlib.pyplot as plt
 
+def show():
+    """Display the current figure buffer in a GUI window."""
+    plt.show()
+
+def xyscatter(x, y, fmt='.', xlabel=None, ylabel=None, title=None, filename=None):
+    """Draw a simple XY scatter plot and optionally saves the plot to *filename*
+    if provided."""
+    fig, ax = create_figure(xlabel, ylabel, title)
+    ax.plot(x, y, fmt)
+    save(fig, filename)
+    return fig
+
 def loglog(x, y, fmt='.', xlabel=None, ylabel=None, title=None, filename=None):
     """Returns a log-log plot and optionally saves the plot to *filename*
     if provided.
     """
-    fig, ax = create_figure()
+    fig, ax = create_figure(xlabel, ylabel, title)
+    ax.loglog(x, y, fmt)
+    save(fig, filename)
+    return fig
+
+def create_figure(xlabel=None, ylabel=None, title=None):
+    """Creates a new figure object. The figure object and the axis of the 
+    figure are returned as a tuple.
+    """
+    fig = plt.figure()
+    ax = fig.add_subplot(111)
     if xlabel: 
         ax.set_xlabel(xlabel)
     if ylabel: 
         ax.set_ylabel(ylabel)
     if title: 
         ax.set_title(title)
-    ax.loglog(x, y, fmt)
-    if filename: 
-        save(fig, filename)
-    return fig
-
-def create_figure():
-    """Creates a new figure object. The figure object and the axis of the 
-    figure are returned as a tuple.
-    """
-    fig = plt.figure()
-    ax = fig.add_subplot(111)
     return fig, ax
 
 def save(fig, filename):
     """Saves a figure object, *fig*, to the location specified by *filename*.
     The extension of *filename* will inform the formatting of the image.
-    """    
-    fig.savefig(filename, dpi=200)
-        
-#def graph_time_to_event(times):
-#    pylab.plot(times.keys(), times.values())   
+    """  
+    if filename:  
+        fig.savefig(filename, dpi=200)
+