当前位置: 首页>>代码示例>>Python>>正文


Python cbook.flatten方法代码示例

本文整理汇总了Python中matplotlib.cbook.flatten方法的典型用法代码示例。如果您正苦于以下问题:Python cbook.flatten方法的具体用法?Python cbook.flatten怎么用?Python cbook.flatten使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.cbook的用法示例。


在下文中一共展示了cbook.flatten方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: normalize_constraint_factor

# 需要导入模块: from matplotlib import cbook [as 别名]
# 或者: from matplotlib.cbook import flatten [as 别名]
def normalize_constraint_factor(self, keys):
        if keys in self._cached_normalizations.keys():
            return self._cached_normalizations[keys]
        else:
            min_accept = 1000
            sampling_chunk = 5000
            samples = self.sample_subset(keys=keys, size=sampling_chunk)
            keep = np.atleast_1d(self.evaluate_constraints(samples))
            if len(keep) == 1:
                return 1
            all_samples = {key: np.array([]) for key in keys}
            while np.count_nonzero(keep) < min_accept:
                samples = self.sample_subset(keys=keys, size=sampling_chunk)
                for key in samples:
                    all_samples[key] = np.hstack(
                        [all_samples[key], samples[key].flatten()])
                keep = np.array(self.evaluate_constraints(all_samples), dtype=bool)
            factor = len(keep) / np.count_nonzero(keep)
            self._cached_normalizations[keys] = factor
            return factor 
开发者ID:lscsoft,项目名称:bilby,代码行数:22,代码来源:dict.py

示例2: get_children

# 需要导入模块: from matplotlib import cbook [as 别名]
# 或者: from matplotlib.cbook import flatten [as 别名]
def get_children(self):
        return list(cbook.flatten(self)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:4,代码来源:container.py

示例3: _update

# 需要导入模块: from matplotlib import cbook [as 别名]
# 或者: from matplotlib.cbook import flatten [as 别名]
def _update(self):
        if self.x is not None and self.y is not None:
            self.X,self.Y = num.meshgridt(self.x, self.y)
            self.xx = self.X.flatten()
            self.yy = self.Y.flatten()
            self.XY = np.array([self.xx, self.yy]).T
        elif self.X is not None and self.Y is not None:
            self.x = self.X[:,0]
            self.xx = self.X.flatten()
            self.y = self.Y[0,:]
            self.yy = self.Y.flatten()
            self.XY = np.array([self.xx, self.yy]).T
        elif self.xx is not None and self.yy is not None:
            self.x = self._unique(self.xx)
            self.y = self._unique(self.yy)
            self.X,self.Y = num.meshgridt(self.x, self.y)
            self.XY = np.array([self.xx, self.yy]).T
        elif self.XY is not None:
            self.xx = self.XY[:,0]
            self.yy = self.XY[:,1]
            self.x = self._unique(self.xx)
            self.y = self._unique(self.yy)
            self.X,self.Y = num.meshgridt(self.x, self.y)
        else:
            raise Exception("cannot determine x and y from input")
        # by now, we have all forms of x and y: x,y; xx,yy; X,Y; XY
        self.nx = len(self.x)
        self.ny = len(self.y)
        # Z is optional
        if self.Z is None:
            if self.zz is not None:
                self.Z = self.zz.reshape(len(self.x), len(self.y))
        else:
            self.zz = self.Z.flatten() 
开发者ID:elcorto,项目名称:pwtools,代码行数:36,代码来源:mpl.py

示例4: remove

# 需要导入模块: from matplotlib import cbook [as 别名]
# 或者: from matplotlib.cbook import flatten [as 别名]
def remove(self):
        for c in cbook.flatten(
                self, scalarp=lambda x: isinstance(x, martist.Artist)):
            if c is not None:
                c.remove()

        if self._remove_method:
            self._remove_method(self) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:10,代码来源:container.py

示例5: get_children

# 需要导入模块: from matplotlib import cbook [as 别名]
# 或者: from matplotlib.cbook import flatten [as 别名]
def get_children(self):
        return [child for child in cbook.flatten(self) if child is not None] 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:4,代码来源:container.py

示例6: __init__

# 需要导入模块: from matplotlib import cbook [as 别名]
# 或者: from matplotlib.cbook import flatten [as 别名]
def __init__(self, line, bands):
        """
        :param line: Line2D
            A line of the x,y nominal values

        :param bands: list of PolyCollections
            The fill_between and/or fill_betweenx PollyCollections spanning the std_devs of the x,y data

        """
        from matplotlib.cbook import flatten
        self.line = line  # matplotlib.lines.Line2D
        self.bands = list(flatten([bands]))  # matplotlib.collections.PolyCollection(s) 
开发者ID:gafusion,项目名称:omas,代码行数:14,代码来源:omas_plot.py

示例7: sample_subset_constrained

# 需要导入模块: from matplotlib import cbook [as 别名]
# 或者: from matplotlib.cbook import flatten [as 别名]
def sample_subset_constrained(self, keys=iter([]), size=None):
        if size is None or size == 1:
            while True:
                sample = self.sample_subset(keys=keys, size=size)
                if self.evaluate_constraints(sample):
                    return sample
        else:
            needed = np.prod(size)
            constraint_keys = list()
            for ii, key in enumerate(keys[-1::-1]):
                if isinstance(self[key], Constraint):
                    constraint_keys.append(-ii - 1)
            for ii in constraint_keys[-1::-1]:
                del keys[ii]
            all_samples = {key: np.array([]) for key in keys}
            _first_key = list(all_samples.keys())[0]
            while len(all_samples[_first_key]) < needed:
                samples = self.sample_subset(keys=keys, size=needed)
                keep = np.array(self.evaluate_constraints(samples), dtype=bool)
                for key in samples:
                    all_samples[key] = np.hstack(
                        [all_samples[key], samples[key][keep].flatten()])
            all_samples = {key: np.reshape(all_samples[key][:needed], size)
                           for key in all_samples
                           if not isinstance(self[key], Constraint)}
            return all_samples 
开发者ID:lscsoft,项目名称:bilby,代码行数:28,代码来源:dict.py

示例8: rescale

# 需要导入模块: from matplotlib import cbook [as 别名]
# 或者: from matplotlib.cbook import flatten [as 别名]
def rescale(self, keys, theta):
        """Rescale samples from unit cube to prior

        Parameters
        ----------
        keys: list
            List of prior keys to be rescaled
        theta: list
            List of randomly drawn values on a unit cube associated with the prior keys

        Returns
        -------
        list: List of floats containing the rescaled sample
        """
        return list(flatten([self[key].rescale(sample) for key, sample in zip(keys, theta)])) 
开发者ID:lscsoft,项目名称:bilby,代码行数:17,代码来源:dict.py

示例9: _makeplot

# 需要导入模块: from matplotlib import cbook [as 别名]
# 或者: from matplotlib.cbook import flatten [as 别名]
def _makeplot(self, ax, fig, data, ymin=None, ymax=None, height=6,
                  width=6, dos=None, color=None):
        """Utility method to tidy phonon band structure diagrams. """
        # Define colours
        if color is None:
            color = 'C0'  # Default to first colour in matplotlib series

        # set x and y limits
        tymax = ymax if (ymax is not None) else max(flatten(data['frequency']))
        tymin = ymin if (ymin is not None) else min(flatten(data['frequency']))
        pad = (tymax - tymin) * 0.05

        if ymin is None:
            ymin = 0 if tymin >= self.imag_tol else tymin - pad
        ymax = ymax if ymax else tymax + pad

        ax.set_ylim(ymin, ymax)
        ax.set_xlim(0, data['distances'][-1][-1])

        if ymin < 0:
            dashline = True
            ax.axhline(0, color=rcParams['grid.color'], linestyle='--',
                       dashes=dashes,
                       zorder=0,
                       linewidth=rcParams['ytick.major.width'])
        else:
            dashline = False

        if dos is not None:
            self._plot_phonon_dos(dos, ax=fig.axes[1], color=color,
                                  dashline=dashline)
        else:

            # keep correct aspect ratio; match axis to canvas
            x0, x1 = ax.get_xlim()
            y0, y1 = ax.get_ylim()

            if width is None:
                width = rcParams['figure.figsize'][0]
            if height is None:
                height = rcParams['figure.figsize'][1]
            ax.set_aspect((height/width) * ((x1-x0)/(y1-y0))) 
开发者ID:SMTG-UCL,项目名称:sumo,代码行数:44,代码来源:phonon_bs_plotter.py


注:本文中的matplotlib.cbook.flatten方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。