mailr26808 - /branches/nmrglue/lib/software/nmrglue.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by tlinnet on November 28, 2014 - 14:32:
Author: tlinnet
Date: Fri Nov 28 14:32:00 2014
New Revision: 26808

URL: http://svn.gna.org/viewcvs/relax?rev=26808&view=rev
Log:
Added initial function in nmrglue module to plot a histogram of the spectrum 
data.

Task #7873 (https://gna.org/task/index.php?7873): Write wrapper function to 
nmrglue, to read .ft2 files and process them.
Homepage: http://www.nmrglue.com/
Link to nmrglue discussion: 
https://groups.google.com/forum/#!forum/nmrglue-discuss
The code is develop at Github: https://github.com/jjhelmus/nmrglue/
Google code: https://code.google.com/p/nmrglue/
Documentation: http://nmrglue.readthedocs.org/en/latest/index.html

Modified:
    branches/nmrglue/lib/software/nmrglue.py

Modified: branches/nmrglue/lib/software/nmrglue.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/nmrglue/lib/software/nmrglue.py?rev=26808&r1=26807&r2=26808&view=diff
==============================================================================
--- branches/nmrglue/lib/software/nmrglue.py    (original)
+++ branches/nmrglue/lib/software/nmrglue.py    Fri Nov 28 14:32:00 2014
@@ -109,6 +109,45 @@
     return ax
 
 
+def hist_plot(ndarray=None, show=False):
+    """Flatten the 2D numpy array, and plot as histogram.
+
+    @keyword ndarray:           The numpy array to flatten, and plot as 
histogram.
+    @type ndarray:              numpy array
+    @keyword show:              A flag which if True will make a call to 
matplotlib.pyplot.show().
+    @type show:                 bool
+    @return:                    The matplotlib.axes.AxesSubplot class, which 
can be manipulated to add additional text to the axis.
+    @rtype:                     matplotlib.axes.AxesSubplot
+    """
+
+    # Flatten the numpy data array.
+    data = ndarray.flatten()
+
+    # Now make a histogram.
+    # http://matplotlib.org/1.2.1/examples/api/histogram_demo.html
+    fig = plt.figure()
+    ax = fig.add_subplot(111)
+
+    #kwargs = {'bins': 3000, 'spam': 'ham'}
+
+    # Make the plot.
+    n, bins, patches = ax.hist(data, bins=1000, range=None, normed=False, 
facecolor='green', alpha=0.75)
+
+    # Calculate the bin centers.
+    bincenters = 0.5*(bins[1:]+bins[:-1])
+
+    # Set limits.
+    ax.set_ylim(0, 10000)
+    ax.set_xlim(-30000, 50000)
+
+    # If show.
+    if show:
+        plt.show()
+
+    # Return ax
+    return ax
+
+
 def read_spectrum(file=None, dir=None):
     """Read the spectrum data.
 




Related Messages


Powered by MHonArc, Updated Fri Nov 28 15:40:02 2014