def Plot(self, Plot=None, **kwargs): """Create a plot for an :class:`xf_Mesh` object. Elements that do not have at least one node within the plot window are not plotted. See :func:`pyxflow.Plot.GetXLims` for a thorough description of how the plot window can be created. :Call: >>> Plot = Mesh.Plot(Plot=None, **kwargs) :Parameters: *Mesh*: :class:`pyxflow.Mesh.xf_Mesh` Mesh to be plotted *Plot*: :class:`pyxflow.Plot.xf_Plot` Overall mesh handle to plot :Returns: *Plot*: :class:`pyxflow.Plot.xf_Plot` Instance of plot class (plot handle) :Kwargs: *order*: :class:`int` Interpolation order for mesh faces *line_options*: :class:`dict` Options for :class:`matplotlib.pyplot.LineCollection` See also kwargs for :func:`pyxflow.Plot.GetXLims` :Examples: The following loads an airfoil mesh and plots the portion of it near the surface of the airfoil. >> Mesh = pyxflow.xf_Mesh("naca_quad.gri") >> Plot = Mesh.Plot(xmin=-0.5, xmax=1.5, ylim=[-0.5,0.5]) The mesh can be plotted from an instance of :class:`pyxflow.All.xf_All` as well. >> All = pyxflow.xf_All(fname="naca_adapt.xfa") >> Plot = All.Mesh.Plot(xlim=[-0.5,1.5,-0.5,0.5]) """ # Process the plot handle. if Plot is None: # Initialize a plot. Plot = xf_Plot() elif not isinstance(Plot, xf_Plot): raise IOError("Plot handle must be instance of " + "pyxflow.plot.xf_Plot") # Use specified defaults for plot window if they exist. kwargs.setdefault('xmindef', Plot.xmin) kwargs.setdefault('xmaxdef', Plot.xmax) # Get the limits based on the Mesh and keyword args xLimMin, xLimMax = GetXLims(self, **kwargs) # Save the plot limits. Plot.xmin = xLimMin Plot.xmax = xLimMax # Check for an existing mesh plot. if Plot.mesh is not None: # Delete it! Plot.mesh.remove() # Determine what figure to use. if kwargs.get('figure') is not None: # Use the input figure. Plot.figure = kwargs['figure'] elif Plot.figure is None: # Follow norms of plotting programs; default is gcf(). Plot.figure = plt.gcf() # Determine what axes to use. if kwargs.get('axes') is not None: # Use the input value. Plot.axes = kwargs['axes'] else: # Normal plotting conventions for default Plot.axes = plt.gca() # Plot order; apparently None leads to default below? Order = kwargs.get('order') # Get the plot data for each element. # It's a list of the node indices in each mesh element. x, y, c = px.MeshPlotData(self._ptr, xLimMin, xLimMax, Order) # Turn this into a list of coordinates. s = [] for f in range(len(c) - 1): s.append(zip(x[c[f]:c[f+1]], y[c[f]:c[f+1]])) # Get any options that should be applied to the actual plot. line_options = kwargs.get('line_options', {}) # Set the default color. line_options.setdefault('colors', (0,0,0,1)) # Create the lines efficiently. hl = LineCollection(s, **line_options) # Plot them. Plot.axes.add_collection(hl) # Apply the bounding box that was created earlier. if kwargs.get('reset_limits', True): Plot.axes.set_xlim(xLimMin[0], xLimMax[0]) Plot.axes.set_ylim(xLimMin[1], xLimMax[1]) # Store the handle to the line collection. Plot.mesh = hl # Draw if necessary. if plt.isinteractive(): plt.draw() # Return the plot handle. return Plot
def Plot(self, scalar=None, **kwargs): """ Plot the mesh and scalar from *xf_All* representation :Call: >>> Plot = All.Plot(scalar=None, **kwargs) :Parameters: *All*: :class:`pyxflow.All.xf_All` Instance of the pyXFlow *xf_All* interface *scalar*: :class:`str` Name of scalar to Plot. A value of ``None`` uses the default scalar. A value of ``False`` prevents plotting of any scalar. :Returns: *Plot*: :class:`pyxflow.Plot.xf_Plot` pyXFlow plot instance with mesh and scalar handles :Kwargs: *mesh*: :class:`bool` Whether or not to plot the mesh *Plot*: :class:`pyxflow.Plot.xf_Plot` Instance of plot class (plot handle) *role*: :class:`str` Identifier for the vector to use for plot The default value is ``'ElemState'``. *order*: :class:`int` Interpolation order for mesh faces *vgroup*: :class:`pyxflow.DataSet.xf_VectorGroup` Vector group to use for plot A value of ``None`` results in using the primal state. The behavior of this keyword argument is subject to change. See also kwargs for * :func:`pyxflow.Plot.GetXLims()` * :func:`pyxflow.Mesh.xf_Mesh.Plot()` * :func:`pyxflow.DataSet.xf_Vector.Plot()` :Examples: The following example loads an airfoil solution and plots the pressure near the surface. >>> All = xf_All("naca_Adapt.xfa") ... >>> All.Plot("Pressure", xlim=[-0.9,1.2,-0.5,0.6]) <pyxflow.Mesh.xf_Mesh instance at ...> :See also: * :func:`pyxflow.Mesh.xf_Mesh.Plot()` * :func:`pyxflow.DataSet.xf_Vector.Plot()` * :func:`pyxflow.DataSet.xf_VectorGroup.Plot()` """ # Versions: # 2013-09-29 @dalle : First version # 2014-02-09 @dalle : Using xf_Vector.Plot() and xf_Mesh.Plot() # Extract the plot handle. Plot = kwargs.get("Plot") # Process the plot handle. if Plot is None: # Initialize a plot. kwargs["Plot"] = xf_Plot() elif not isinstance(Plot, xf_Plot): raise IOError("Plot handle must be instance of " + "pyxflow.Plot.xf_Plot") # Determine the vector group to use. vgroup = kwargs.get("vgroup") if vgroup is None: # Use the default vector group (PrimalState). UG = self.GetPrimalState() else: # Find the vector group by name UG = self.GetVectorGroup(vgroup) # Plot the mesh. if kwargs.get("mesh", True) is True: kwargs["Plot"] = self.Mesh.Plot(**kwargs) # Plot the scalar. if scalar is not False and UG is not None: kwargs["scalar"] = scalar kwargs["Plot"] = UG.Plot(self.Mesh, self.EqnSet, **kwargs) # Return the plot handle. return kwargs["Plot"]