[cig-commits] [commit] master: py: Simplify grid plotting. (77b3eb7)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Wed Jan 14 09:29:27 PST 2015


Repository : https://github.com/geodynamics/specfem1d

On branch  : master
Link       : https://github.com/geodynamics/specfem1d/compare/2ccfba13481e26296eebf034518cd31d2c727906...33b512de01491f2c70de206939855d95b22febf4

>---------------------------------------------------------------

commit 77b3eb7ab50386d429111539e5cbc9f6b8ad0e04
Author: Elliott Sales de Andrade <esalesde at physics.utoronto.ca>
Date:   Thu Jan 8 21:10:39 2015 -0500

    py: Simplify grid plotting.
    
    Remove unnecessary loops to speed things up. Remove mixing of
    object-oriented and pylab interfaces to matplotlib. Put x grid on the
    minor ticks, so that matplotlib will still automatically create the
    x-axis labels.


>---------------------------------------------------------------

77b3eb7ab50386d429111539e5cbc9f6b8ad0e04
 Python_version/grid.py | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/Python_version/grid.py b/Python_version/grid.py
index 8eb60d1..34e30c2 100644
--- a/Python_version/grid.py
+++ b/Python_version/grid.py
@@ -53,28 +53,28 @@ class OneDimensionalGrid(object):
         self.dXdKsi = gll.jacobian(self.ticks, param)
         self.dKsiDx = gll.jacobian_inverse(self.ticks, param)
 
-    def plot(self, fig=0):
+    def plot(self):
         """Plot the grid
         my_ticks gives the abscissa of the borders
         TODO I should test : _the types of the parameters
                              _their sizes"""
         import matplotlib.pyplot as plt
-        plt.figure(fig)
-        sub1=plt.subplot(211)
-        plt.hold(True)
-        for e in np.arange(self.param.nSpec):
-            for i in np.arange(self.param.nGLL):
-                plt.plot(self.z[self.param.ibool[e,i]],self.rho[e,i],'b+')
-        sub1.set_title(r'$\rho(z)$')
-        plt.xticks(self.ticks)
-        plt.grid(True)
-        sub2=plt.subplot(212)
-        for e in np.arange(self.param.nSpec):
-            for i in np.arange(self.param.nGLL):
-                plt.plot(self.z[self.param.ibool[e,i]],self.mu[e,i],'r+')
-        sub2.set_title(r'$\mu(z)$')
-        plt.suptitle(" Grid ")
-        plt.xticks(self.ticks)
-        plt.grid(True)
+        from matplotlib.ticker import FixedLocator
+
+        fig, ax = plt.subplots(2, 1, sharex=True)
+
+        ax[0].plot(self.z[self.param.ibool].flat, self.rho.flat, 'b+')
+        ax[0].set_title(r'$\rho(z)$')
+        ax[0].xaxis.set_minor_locator(FixedLocator(self.ticks))
+        ax[0].xaxis.grid(True, which='minor', alpha=0.5)
+        ax[0].yaxis.grid(True)
+
+        ax[1].plot(self.z[self.param.ibool].flat, self.mu.flat, 'r+')
+        ax[1].set_title(r'$\mu(z)$')
+        ax[1].xaxis.set_minor_locator(FixedLocator(self.ticks))
+        ax[1].xaxis.grid(True, which='minor', alpha=0.5)
+        ax[1].yaxis.grid(True)
+
+        plt.suptitle('Grid')
+
         plt.show()
-        plt.hold(False)



More information about the CIG-COMMITS mailing list