• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python cbook.delete_masked_points函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中matplotlib.cbook.delete_masked_points函数的典型用法代码示例。如果您正苦于以下问题:Python delete_masked_points函数的具体用法?Python delete_masked_points怎么用?Python delete_masked_points使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: set_UVC

    def set_UVC(self, U, V, C=None):
        self.u = ma.masked_invalid(U, copy=False).ravel()
        self.v = ma.masked_invalid(V, copy=False).ravel()
        if C is not None:
            c = ma.masked_invalid(C, copy=False).ravel()
            x, y, u, v, c = delete_masked_points(self.x.ravel(),
                                                 self.y.ravel(),
                                                 self.u, self.v, c)
        else:
            x, y, u, v = delete_masked_points(self.x.ravel(), self.y.ravel(),
                                              self.u, self.v)

        magnitude = np.hypot(u, v)
        flags, barbs, halves, empty = self._find_tails(magnitude,
                                                       self.rounding,
                                                       **self.barb_increments)

        # Get the vertices for each of the barbs

        plot_barbs = self._make_barbs(u, v, flags, barbs, halves, empty,
                                      self._length, self._pivot, self.sizes,
                                      self.fill_empty, self.flip)
        self.set_verts(plot_barbs)

        # Set the color array
        if C is not None:
            self.set_array(c)

        # Update the offsets in case the masked data changed
        xy = np.hstack((x[:, np.newaxis], y[:, np.newaxis]))
        self._offsets = xy
开发者ID:AmitAronovitch,项目名称:matplotlib,代码行数:31,代码来源:quiver.py


示例2: test_string_seq

 def test_string_seq(self):
     a1 = ['a', 'b', 'c', 'd', 'e', 'f']
     a2 = [1, 2, 3, np.nan, np.nan, 6]
     result1, result2 = delete_masked_points(a1, a2)
     ind = [0, 1, 2, 5]
     assert_array_equal(result1, np.array(a1)[ind])
     assert_array_equal(result2, np.array(a2)[ind])
开发者ID:QuLogic,项目名称:matplotlib,代码行数:7,代码来源:test_cbook.py


示例3: test_rgba

 def test_rgba(self):
     a_masked = np.ma.array([1, 2, 3, np.nan, np.nan, 6],
                            mask=[False, False, True, True, False, False])
     a_rgba = mcolors.to_rgba_array(['r', 'g', 'b', 'c', 'm', 'y'])
     actual = delete_masked_points(a_masked, a_rgba)
     ind = [0, 1, 5]
     assert_array_equal(actual[0], a_masked[ind].compressed())
     assert_array_equal(actual[1], a_rgba[ind])
开发者ID:QuLogic,项目名称:matplotlib,代码行数:8,代码来源:test_cbook.py


示例4: test_datetime

 def test_datetime(self):
     dates = [datetime(2008, 1, 1), datetime(2008, 1, 2),
              datetime(2008, 1, 3), datetime(2008, 1, 4),
              datetime(2008, 1, 5), datetime(2008, 1, 6)]
     a_masked = np.ma.array([1, 2, 3, np.nan, np.nan, 6],
                            mask=[False, False, True, True, False, False])
     actual = delete_masked_points(dates, a_masked)
     ind = [0, 1, 5]
     assert_array_equal(actual[0], np.array(dates)[ind])
     assert_array_equal(actual[1], a_masked[ind].compressed())
开发者ID:QuLogic,项目名称:matplotlib,代码行数:10,代码来源:test_cbook.py


示例5: text_plot

def text_plot(ax, x, y, data, format='%.0f', loc=None, **kw):
    from matplotlib.cbook import delete_masked_points
    from matplotlib import transforms

    # Default to centered on point
    if loc is not None:
        x0,y0 = loc
        trans = ax.transData + transforms.Affine2D().translate(x0, y0)
    else:
        trans = ax.transData

    # Handle both callables and strings for format
    if is_string_like(format):
        formatter = lambda s: format % s
    else:
        formatter = format

    # Handle masked arrays
    x,y,data = delete_masked_points(x, y, data)

    # If there is nothing left after deleting the masked points, return None
    if not data.any():
        return None

    # Make the TextCollection object
    texts = [formatter(d) for d in data]
    text_obj = TextCollection(x, y, texts, horizontalalignment='center',
        verticalalignment='center', clip_on=True, transform=trans, **kw)

    # Add it to the axes
    ax.add_artist(text_obj)

    # Update plot range
    minx = np.min(x)
    maxx = np.max(x)
    miny = np.min(y)
    maxy = np.max(y)
    w = maxx - minx
    h = maxy - miny

    # the pad is a little hack to deal with the fact that we don't
    # want to transform all the symbols whose scales are in points
    # to data coords to get the exact bounding box for efficiency
    # reasons.  It can be done right if this is deemed important
    padx, pady = 0.05*w, 0.05*h
    corners = (minx-padx, miny-pady), (maxx+padx, maxy+pady)
    ax.update_datalim(corners)
    ax.autoscale_view()
    return text_obj
开发者ID:rayg-ssec,项目名称:MetPy,代码行数:49,代码来源:plots.py


示例6: set_offsets

    def set_offsets(self, xy):
        """
        Set the offsets for the barb polygons.  This saves the offsets passed
        in and actually sets version masked as appropriate for the existing
        U/V data. *offsets* should be a sequence.

        ACCEPTS: sequence of pairs of floats
        """
        self.x = xy[:, 0]
        self.y = xy[:, 1]
        x, y, u, v = delete_masked_points(self.x.ravel(), self.y.ravel(),
                                          self.u, self.v)
        _check_consistent_shapes(x, y, u, v)
        xy = np.column_stack((x, y))
        mcollections.PolyCollection.set_offsets(self, xy)
        self.stale = True
开发者ID:DanHickstein,项目名称:matplotlib,代码行数:16,代码来源:quiver.py


示例7: set_offsets

    def set_offsets(self, xy):
        """
        Set the offsets for the barb polygons.  This saves the offsets passed
        in and masks them as appropriate for the existing U/V data.

        Parameters
        ----------
        xy : sequence of pairs of floats
        """
        self.x = xy[:, 0]
        self.y = xy[:, 1]
        x, y, u, v = cbook.delete_masked_points(
            self.x.ravel(), self.y.ravel(), self.u, self.v)
        _check_consistent_shapes(x, y, u, v)
        xy = np.column_stack((x, y))
        mcollections.PolyCollection.set_offsets(self, xy)
        self.stale = True
开发者ID:QuLogic,项目名称:matplotlib,代码行数:17,代码来源:quiver.py


示例8: scatter

    def scatter(self, xs, ys, zs=0, zdir='z', s=20, c='b', *args, **kwargs):
        '''
        Create a scatter plot.

        ==========  ==========================================================
        Argument    Description
        ==========  ==========================================================
        *xs*, *ys*  Positions of data points.
        *zs*        Either an array of the same length as *xs* and
                    *ys* or a single value to place all points in
                    the same plane. Default is 0.
        *zdir*      Which direction to use as z ('x', 'y' or 'z')
                    when plotting a 2d set.
        *s*         size in points^2.  It is a scalar or an array of the same
                    length as *x* and *y*.

        *c*         a color. *c* can be a single color format string, or a
                    sequence of color specifications of length *N*, or a
                    sequence of *N* numbers to be mapped to colors using the
                    *cmap* and *norm* specified via kwargs (see below). Note
                    that *c* should not be a single numeric RGB or RGBA
                    sequence because that is indistinguishable from an array
                    of values to be colormapped.  *c* can be a 2-D array in
                    which the rows are RGB or RGBA, however.
        ==========  ==========================================================

        Keyword arguments are passed on to
        :func:`~matplotlib.axes.Axes.scatter`.

        Returns a :class:`~mpl_toolkits.mplot3d.art3d.Patch3DCollection`
        '''

        had_data = self.has_data()

        xs = np.ma.ravel(xs)
        ys = np.ma.ravel(ys)
        zs = np.ma.ravel(zs)
        if xs.size != ys.size:
            raise ValueError("x and y must be the same size")
        if xs.size != zs.size and zs.size == 1:
            zs = np.array(zs[0] * xs.size)

        s = np.ma.ravel(s)  # This doesn't have to match x, y in size.

        cstr = cbook.is_string_like(c) or cbook.is_sequence_of_strings(c)
        if not cstr:
            c = np.asanyarray(c)
            if c.size == xs.size:
                c = np.ma.ravel(c)

        xs, ys, zs, s, c = cbook.delete_masked_points(xs, ys, zs, s, c)

        patches = Axes.scatter(self, xs, ys, s=s, c=c, *args, **kwargs)
        if not cbook.iterable(zs):
            is_2d = True
            zs = np.ones(len(xs)) * zs
        else:
            is_2d = False
        art3d.patch_collection_2d_to_3d(patches, zs=zs, zdir=zdir)

        #FIXME: why is this necessary?
        if not is_2d:
            self.auto_scale_xyz(xs, ys, zs, had_data)

        return patches
开发者ID:CTPUG,项目名称:matplotlib,代码行数:65,代码来源:axes3d.py


示例9: test_bad_first_arg

 def test_bad_first_arg(self):
     with pytest.raises(ValueError):
         delete_masked_points('a string', np.arange(1.0, 7.0))
开发者ID:QuLogic,项目名称:matplotlib,代码行数:3,代码来源:test_cbook.py


示例10: hexplot

def hexplot(axis, x, y, z, extent=None,
           cmap=None, norm=None, vmin=None, vmax=None,
           alpha=None, linewidths=None, edgecolors='none',
           **kwargs):

    if not axis._hold:
        axis.cla()

    axis._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)

    x, y, z = cbook.delete_masked_points(x, y, z)

    x = np.array(x, float)
    y = np.array(y, float)

    # hardcoded
    sx = (2 * 0.465) * 0.99
    sy = (2 * 0.268) * 0.99

    if extent is not None:
        xmin, xmax, ymin, ymax = extent
    else:
        xmin, xmax = (np.amin(x-sx), np.amax(x+sx)) if len(x) else (0, 1)
        ymin, ymax = (np.amin(y-sy), np.amax(y+sy)) if len(y) else (0, 1)

        # to avoid issues with singular data, expand the min/max pairs
        xmin, xmax = mtrans.nonsingular(xmin, xmax, expander=0.1)
        ymin, ymax = mtrans.nonsingular(ymin, ymax, expander=0.1)

    padding = 1.e-9 * (xmax - xmin)
    xmin -= padding
    xmax += padding

    n = len(x)
    polygon = np.zeros((6, 2), float)
    polygon[:, 0] = sx * np.array([-0.5, 0.5, 1.0, 0.5, -0.5, -1.0]) / 3.0
    polygon[:, 1] = sy * np.array([0.5, 0.5, 0.0, -0.5, -0.5, 0.0])

    #S = math.sqrt(3) / 2
    #polygon[:, 0] = sx * np.array([-0.5, 0.5, 1.0, 0.5, -0.5, -1.0])
    #polygon[:, 1] = sy * np.array([S, S, 0.0, -S, -S, 0.0])

    offsets = np.zeros((n, 2), float)
    offsets[:, 0] = x
    offsets[:, 1] = y

    collection = mcoll.PolyCollection(
        [polygon],
        edgecolors=edgecolors,
        linewidths=linewidths,
        offsets=offsets,
        transOffset=mtransforms.IdentityTransform(),
        offset_position="data"
        )

    if isinstance(norm, mcolors.LogNorm):
        if (z == 0).any():
            # make sure we have not zeros
            z += 1

    if norm is not None:
        if norm.vmin is None and norm.vmax is None:
            norm.autoscale(z)

    if norm is not None and not isinstance(norm, mcolors.Normalize):
        msg = "'norm' must be an instance of 'mcolors.Normalize'"
        raise ValueError(msg)

    collection.set_array(z)
    collection.set_cmap(cmap)
    collection.set_norm(norm)
    collection.set_alpha(alpha)
    collection.update(kwargs)

    if vmin is not None or vmax is not None:
        collection.set_clim(vmin, vmax)
    else:
        collection.autoscale_None()

    corners = ((xmin, ymin), (xmax, ymax))
    axis.update_datalim(corners)
    axis.autoscale_view(tight=True)

    # add the collection last
    axis.add_collection(collection, autolim=False)
    return collection
开发者ID:nicocardiel,项目名称:megaradrp,代码行数:86,代码来源:visualization.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python cbook.dmp函数代码示例发布时间:2022-05-27
下一篇:
Python cbook.dedent函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap