2013-06-14 5 views
2

주어진 도메인에서 기하학적으로 다양한 두 개의 독립 변수를 풀려고합니다. 단일 뷰어 디스플레이에 분산을 표시하려고합니다. 단일 뷰어 상자의 독립 변수에 대해 두 가지 윤곽 플롯을 각각 하나씩 얻으려면 어떻게해야합니까? 이중 윤곽에 대해 다음 코드를 사용했지만 두 변수 (phasegamma 및 phaseigma)에 대해 다른 윤곽을 얻을 수 없습니다. 한 줄거리에서 두 등고선을 얻는 방법을 수정하거나 다른 방법으로 제안하십시오.단일 뷰어에서 두 개의 윤곽 플롯 - Python FiPy

ImportError를 제외한
import pylab 
class PhaseViewer(Matplotlib2DGridViewer): 
    def __init__(self, phasesigma, phasegamma, title = None, limits ={}, **kwlimits): 
     self.phasesigma = phasesigma 
     self.contour1 = None 
     self.phasegamma = phasegamma 
     self.contour2 = None 

     Matplotlib2DGridViewer.__init__(self, vars=(1-phasegamma-phasesigma),title=title,cmap=pylab.cm.hot,limits ={}, **kwlimits) 
    def _plot(self): 
     Matplotlib2DGridViewer._plot(self) 

     if self.contour1 is not None or self.contour2 is not None: 
      for Ccr in self.contour1.collections: 
        Ccr.remove() 
      for Cni in self.contour1.collections: 
        Cni.remove()  
     mesh = self.phasesigma.getMesh() 
     mesh2 = self.phasegamma.getMesh() 
     shape = mesh.getShape() 
     shape2 = mesh2.getShape() 
     x, y = mesh.getCellCenters() 
     z = self.phasesigma.getValue() 
     x, y, z = [a.reshape(shape, order="FORTRAN") for a in (x, y, z)] 
     self.contour1 = pylab.contour(x, y, z, (0.5,)) 
     l, m = mesh1.getCellCenters() 
     w = self.phasegamma.getValue() 
     l, m, w = [b.reshape(shape, order ="FORTRAN") for b in (l, m, w)] 
     self.contour2 = pylab.contour(l, m, w, (0.5,)) 
     raw_input("check2") 

viewer = PhaseViewer(phasesigma=phasesigma, phasegamma=phasegamma,\ 
      title = r"%s & %s" % (phasegamma.name, phasesigma.name), datamin=0., datamax=1.) 

:. 뷰어 = 멀티 뷰어 (시청자 = (뷰어 (바르 = phasesigma, datamin = 0, datamax = 1), 뷰어 (= phasegamma, datamin = 0, 바르 datamax = 1)))

+0

당신이 단지의 일반 쌍에'contour'를 사용하여 메시를하려 시도 되세요'오히려 Matplotlib2DGridViewer'보다, 축 matplotlib' '? –

+0

아니요, 일반적인 matplotlib 축으로 시도하지 않았습니다. – bvspavan89

답변

2

방금 ​​본 것이므로 잘하면 여전히 유용합니다. 필자는 왜 당신의 버전이 작동하지 않았는지 확신하지 못한다. 비록 필라브가 너무 높은 수준에서 작동하고 너무 많은 것들이 자동적으로 발생한다고 나는 일반적으로 알지만.

내가 Matplotlib2DContourViewer에서 다음을 기반으로 당신이 원하는 것을 할 것 같다 :

class PhaseViewer(Matplotlib2DGridViewer): 
    def __init__(self, phasesigma, phasegamma, title = None, limits ={}, **kwlimits): 
     self.phasesigma = phasesigma 
     self.contour1 = None 
     self.phasegamma = phasegamma 
     self.contour2 = None 
     self.number = 10 
     self.levels = None 

     Matplotlib2DGridViewer.__init__(self, vars=(1-phasegamma-phasesigma),title=title,cmap=pylab.cm.hot,limits ={}, **kwlimits) 
    def _plot(self): 
     Matplotlib2DGridViewer._plot(self) 

     if hasattr(self, "_contourSet"): 
      for countourSet in self._contourSet: 
       for collection in ccontourSet.collections: 
        try: 
         ix = self.axes.collections.index(collection) 
        except ValueError, e: 
         ix = None 

        if ix is not None: 
         del self.axes.collections[ix] 
     self._contourSet = [] 

     for var in (self.phasesigma, self.phasegamma): 
      mesh = var.mesh 
      x, y = mesh.cellCenters 
      z = var.value 

      xmin, ymin = mesh.extents['min'] 
      xmax, ymax = mesh.extents['max'] 

      from matplotlib.mlab import griddata 

      xi = fp.numerix.linspace(xmin, xmax, 1000) 
      yi = fp.numerix.linspace(ymin, ymax, 1000) 
      # grid the data. 
      zi = griddata(x, y, z, xi, yi, interp='linear') 


      zmin, zmax = self._autoscale(vars=[var], 
             datamin=self._getLimit(('datamin', 'zmin')), 
             datamax=self._getLimit(('datamax', 'zmax'))) 

      self.norm.vmin = zmin 
      self.norm.vmax = zmax 

      if self.levels is not None: 
       levels = self.levels 
      else: 
       levels = fp.numerix.arange(self.number + 1) * (zmax - zmin)/self.number + zmin 


      self._contourSet.append(self.axes.contour(xi, yi, zi, levels=levels, cmap=self.cmap)) 

     self.axes.set_xlim(xmin=self._getLimit('xmin'), 
          xmax=self._getLimit('xmax')) 

     self.axes.set_ylim(ymin=self._getLimit('ymin'), 
          ymax=self._getLimit('ymax')) 

     if self.colorbar is not None: 
       self.colorbar.plot()