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


Python pyplot.contourf方法代码示例

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


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

示例1: show_decision_boundary

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contourf [as 别名]
def show_decision_boundary(self, model):
        h = 0.001
        x, y = np.meshgrid(np.arange(-1, 1, h), np.arange(-1, 1, h))
        out = model(Tensor(np.c_[x.ravel(), y.ravel()]))
        pred = np.argmax(out.data, axis=1)
        if gpu:
            plt.contourf(to_cpu(x), to_cpu(y), to_cpu(pred.reshape(x.shape)))
            for c in range(self.num_class):
                plt.scatter(to_cpu(self.data[(self.label[:,c]>0)][:,0]),to_cpu(self.data[(self.label[:,c]>0)][:,1]))
        else:
            plt.contourf(x, y, pred.reshape(x.shape))
            for c in range(self.num_class):
                plt.scatter(self.data[(self.label[:,c]>0)][:,0],self.data[(self.label[:,c]>0)][:,1])
        plt.xlim(-1,1)
        plt.ylim(-1,1)
        plt.axis('off')
        plt.show() 
开发者ID:Kashu7100,项目名称:Qualia2.0,代码行数:19,代码来源:basic.py

示例2: plot_f

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contourf [as 别名]
def plot_f(f, filenm='test_function.eps'):
    # only for 2D functions
    import matplotlib.pyplot as plt
    import matplotlib
    font = {'size': 20}
    matplotlib.rc('font', **font)

    delta = 0.005
    x = np.arange(0.0, 1.0, delta)
    y = np.arange(0.0, 1.0, delta)
    nx = len(x)
    X, Y = np.meshgrid(x, y)

    xx = np.array((X.ravel(), Y.ravel())).T
    yy = f(xx)

    plt.figure()
    plt.contourf(X, Y, yy.reshape(nx, nx), levels=np.linspace(yy.min(), yy.max(), 40))
    plt.xlim([0, 1])
    plt.ylim([0, 1])
    plt.colorbar()
    plt.scatter(f.argmax[0], f.argmax[1], s=180, color='k', marker='+')
    plt.savefig(filenm) 
开发者ID:zi-w,项目名称:Ensemble-Bayesian-Optimization,代码行数:25,代码来源:simple_functions.py

示例3: visualizeFit

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contourf [as 别名]
def visualizeFit(X,mu,sigma2):
    x = np.arange(0, 36, 0.5) # 0-36,步长0.5
    y = np.arange(0, 36, 0.5)
    X1,X2 = np.meshgrid(x,y)  # 要画等高线,所以meshgird
    Z = multivariateGaussian(np.hstack((X1.reshape(-1,1),X2.reshape(-1,1))), mu, sigma2)  # 计算对应的高斯分布函数
    Z = Z.reshape(X1.shape)  # 调整形状
    plt.plot(X[:,0],X[:,1],'bx')
    
    if np.sum(np.isinf(Z).astype(float)) == 0:   # 如果计算的为无穷,就不用画了
        #plt.contourf(X1,X2,Z,10.**np.arange(-20, 0, 3),linewidth=.5)
        CS = plt.contour(X1,X2,Z,10.**np.arange(-20, 0, 3),color='black',linewidth=.5)   # 画等高线,Z的值在10.**np.arange(-20, 0, 3)
        #plt.clabel(CS)
            
    plt.show()

# 选择最优的epsilon,即:使F1Score最大 
开发者ID:lawlite19,项目名称:MachineLearning_Python,代码行数:18,代码来源:AnomalyDetection.py

示例4: contour_pressure

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contourf [as 别名]
def contour_pressure(self):
        """

        Returns:

        """
        try:
            import pylab as plt
        except ImportError:
            import matplotlib.pyplot as plt
        x, y = self.meshgrid()
        p_coeff = np.polyfit(self.volumes, self.pressure.T, deg=self._fit_order)
        p_grid = np.array([np.polyval(p_coeff, v) for v in self._volumes]).T
        plt.contourf(x, y, p_grid)
        plt.plot(self.get_minimum_energy_path(), self.temperatures)
        plt.xlabel("Volume [$\AA^3$]")
        plt.ylabel("Temperature [K]") 
开发者ID:pyiron,项目名称:pyiron,代码行数:19,代码来源:thermo_bulk.py

示例5: contour_entropy

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contourf [as 别名]
def contour_entropy(self):
        """

        Returns:

        """
        try:
            import pylab as plt
        except ImportError:
            import matplotlib.pyplot as plt
        s_coeff = np.polyfit(self.volumes, self.entropy.T, deg=self._fit_order)
        s_grid = np.array([np.polyval(s_coeff, v) for v in self.volumes]).T
        x, y = self.meshgrid()
        plt.contourf(x, y, s_grid)
        plt.plot(self.get_minimum_energy_path(), self.temperatures)
        plt.xlabel("Volume [$\AA^3$]")
        plt.ylabel("Temperature [K]") 
开发者ID:pyiron,项目名称:pyiron,代码行数:19,代码来源:thermo_bulk.py

示例6: plot_contourf

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contourf [as 别名]
def plot_contourf(self, ax=None, show_min_erg_path=False):
        """

        Args:
            ax:
            show_min_erg_path:

        Returns:

        """
        try:
            import pylab as plt
        except ImportError:
            import matplotlib.pyplot as plt
        x, y = self.meshgrid()
        if ax is None:
            fig, ax = plt.subplots(1, 1)
        ax.contourf(x, y, self.energies)
        if show_min_erg_path:
            plt.plot(self.get_minimum_energy_path(), self.temperatures, "w--")
        plt.xlabel("Volume [$\AA^3$]")
        plt.ylabel("Temperature [K]")
        return ax 
开发者ID:pyiron,项目名称:pyiron,代码行数:25,代码来源:thermo_bulk.py

示例7: test_given_colors_levels_and_extends

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contourf [as 别名]
def test_given_colors_levels_and_extends():
    _, axes = plt.subplots(2, 4)

    data = np.arange(12).reshape(3, 4)

    colors = ['red', 'yellow', 'pink', 'blue', 'black']
    levels = [2, 4, 8, 10]

    for i, ax in enumerate(axes.flatten()):
        plt.sca(ax)

        filled = i % 2 == 0.
        extend = ['neither', 'min', 'max', 'both'][i // 2]

        if filled:
            last_color = -1 if extend in ['min', 'max'] else None
            plt.contourf(data, colors=colors[:last_color], levels=levels,
                         extend=extend)
        else:
            last_level = -1 if extend == 'both' else None
            plt.contour(data, colors=colors, levels=levels[:last_level],
                        extend=extend)

        plt.colorbar() 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:26,代码来源:test_contour.py

示例8: test_contour_datetime_axis

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contourf [as 别名]
def test_contour_datetime_axis():
    fig = plt.figure()
    fig.subplots_adjust(hspace=0.4, top=0.98, bottom=.15)
    base = datetime.datetime(2013, 1, 1)
    x = np.array([base + datetime.timedelta(days=d) for d in range(20)])
    y = np.arange(20)
    z1, z2 = np.meshgrid(np.arange(20), np.arange(20))
    z = z1 * z2
    plt.subplot(221)
    plt.contour(x, y, z)
    plt.subplot(222)
    plt.contourf(x, y, z)
    x = np.repeat(x[np.newaxis], 20, axis=0)
    y = np.repeat(y[:, np.newaxis], 20, axis=1)
    plt.subplot(223)
    plt.contour(x, y, z)
    plt.subplot(224)
    plt.contourf(x, y, z)
    for ax in fig.get_axes():
        for label in ax.get_xticklabels():
            label.set_ha('right')
            label.set_rotation(30) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:24,代码来源:test_contour.py

示例9: test_colorbar_get_ticks

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contourf [as 别名]
def test_colorbar_get_ticks():
    # test feature for #5792
    plt.figure()
    data = np.arange(1200).reshape(30, 40)
    levels = [0, 200, 400, 600, 800, 1000, 1200]

    plt.subplot()
    plt.contourf(data, levels=levels)

    # testing getter for user set ticks
    userTicks = plt.colorbar(ticks=[0, 600, 1200])
    assert userTicks.get_ticks().tolist() == [0, 600, 1200]

    # testing for getter after calling set_ticks
    userTicks.set_ticks([600, 700, 800])
    assert userTicks.get_ticks().tolist() == [600, 700, 800]

    # testing for getter after calling set_ticks with some ticks out of bounds
    userTicks.set_ticks([600, 1300, 1400, 1500])
    assert userTicks.get_ticks().tolist() == [600]

    # testing getter when no ticks are assigned
    defTicks = plt.colorbar(orientation='horizontal')
    assert defTicks.get_ticks().tolist() == levels 
开发者ID:holzschu,项目名称:python3_ios,代码行数:26,代码来源:test_colorbar.py

示例10: test_given_colors_levels_and_extends

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contourf [as 别名]
def test_given_colors_levels_and_extends():
    _, axes = plt.subplots(2, 4)

    data = np.arange(12).reshape(3, 4)

    colors = ['red', 'yellow', 'pink', 'blue', 'black']
    levels = [2, 4, 8, 10]

    for i, ax in enumerate(axes.flatten()):
        filled = i % 2 == 0.
        extend = ['neither', 'min', 'max', 'both'][i // 2]

        if filled:
            # If filled, we have 3 colors with no extension,
            # 4 colors with one extension, and 5 colors with both extensions
            first_color = 1 if extend in ['max', 'neither'] else None
            last_color = -1 if extend in ['min', 'neither'] else None
            c = ax.contourf(data, colors=colors[first_color:last_color],
                            levels=levels, extend=extend)
        else:
            # If not filled, we have 4 levels and 4 colors
            c = ax.contour(data, colors=colors[:-1],
                           levels=levels, extend=extend)

        plt.colorbar(c, ax=ax) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:27,代码来源:test_contour.py

示例11: plot_heatmap

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contourf [as 别名]
def plot_heatmap(self, data_matrix, title="", xlab="", ylab="", colormap=plt.cm.jet):
        """Plot heatmap of data matrix.

        :param self: object.
        :param data_matrix: 2D array to be plotted.
        :param title: Figure title.
        :param xlab: X axis label.
        :param ylab: Y axis label.
        :param colormap: matplotlib color map.
        :retuns: None
        :rtype: object
        """
        """
        """
        fig = plt.figure()

        p = plt.contourf(data_matrix)
        plt.colorbar(p, orientation='vertical', cmap=colormap)

        self._set_properties_and_close(fig, title, xlab, ylab) 
开发者ID:nanoporetech,项目名称:wub,代码行数:22,代码来源:report.py

示例12: plot_decision_boundary

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contourf [as 别名]
def plot_decision_boundary(pred_func, X, y, title=None):
    """分类器画图函数,可画出样本点和决策边界
    :param pred_func: predict函数
    :param X: 训练集X
    :param y: 训练集Y
    :return: None
    """

    # Set min and max values and give it some padding
    x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5
    y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5
    h = 0.01
    # Generate a grid of points with distance h between them
    xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
    # Predict the function value for the whole gid
    Z = pred_func(np.c_[xx.ravel(), yy.ravel()])
    Z = Z.reshape(xx.shape)
    # Plot the contour and training examples
    plt.contourf(xx, yy, Z, cmap=plt.cm.Spectral)
    plt.scatter(X[:, 0], X[:, 1], s=40, c=y, cmap=plt.cm.Spectral)

    if title:
        plt.title(title)
    plt.show() 
开发者ID:WiseDoge,项目名称:plume,代码行数:26,代码来源:utils.py

示例13: plot

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contourf [as 别名]
def plot(X,Y,pred_func):
    # determine canvas borders
    mins = np.amin(X,0); 
    mins = mins - 0.1*np.abs(mins);
    maxs = np.amax(X,0); 
    maxs = maxs + 0.1*maxs;

    ## generate dense grid
    xs,ys = np.meshgrid(np.linspace(mins[0,0],maxs[0,0],300), 
            np.linspace(mins[0,1], maxs[0,1], 300));


    # evaluate model on the dense grid
    Z = pred_func(np.c_[xs.flatten(), ys.flatten()]);
    Z = Z.reshape(xs.shape)

    # Plot the contour and training examples
    plt.contourf(xs, ys, Z, cmap=plt.cm.Spectral)
    plt.scatter(X[:, 0], X[:, 1], c=Y[:,1], s=50,
            cmap=colors.ListedColormap(['orange', 'blue']))
    plt.show() 
开发者ID:jasonbaldridge,项目名称:try-tf,代码行数:23,代码来源:plot_boundary_on_data.py

示例14: plot

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contourf [as 别名]
def plot(self, level_set=True):
        import matplotlib.pyplot as plt

        x0, x1, y0, y1 = self.bounding_box

        w = x1 - x0
        h = x1 - x0
        x = numpy.linspace(x0 - w * 0.1, x1 + w * 0.1, 101)
        y = numpy.linspace(y0 - h * 0.1, y1 + h * 0.1, 101)
        X, Y = numpy.meshgrid(x, y)

        Z = self.dist(numpy.array([X, Y]))

        if level_set:
            alpha = max([abs(numpy.min(Z)), abs(numpy.min(Z))])
            cf = plt.contourf(
                X, Y, Z, levels=20, cmap=plt.cm.coolwarm, vmin=-alpha, vmax=alpha
            )
            plt.colorbar(cf)

        # mark the 0-level (the domain boundary)
        plt.contour(X, Y, Z, levels=[0.0], colors="k")

        plt.gca().set_aspect("equal") 
开发者ID:nschloe,项目名称:dmsh,代码行数:26,代码来源:geometry.py

示例15: plot_proba_map

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import contourf [as 别名]
def plot_proba_map(i, lat,lon, clusters, class_prob, label,
                   lat_event, lon_event):

    plt.clf()
    class_prob = class_prob / np.sum(class_prob)
    assert np.isclose(np.sum(class_prob),1)
    risk_map = np.zeros_like(clusters,dtype=np.float64)
    for cluster_id in range(len(class_prob)):
        x,y = np.where(clusters == cluster_id)
        risk_map[x,y] = class_prob[cluster_id]

    plt.contourf(lon,lat,risk_map,cmap='YlOrRd',alpha=0.9,
                 origin='lower',vmin=0.0,vmax=1.0)
    plt.colorbar()

    plt.plot(lon_event, lat_event, marker='+',c='k',lw='5')
    plt.contour(lon,lat,clusters,colors='k',hold='on')
    plt.xlim((min(lon),max(lon)))
    plt.ylim((min(lat),max(lat)))
    png_name = os.path.join(args.output,
                    '{}_pred_{}_label_{}.eps'.format(i,np.argmax(class_prob),
                                                     label))
    plt.savefig(png_name)
    plt.close() 
开发者ID:tperol,项目名称:ConvNetQuake,代码行数:26,代码来源:misclassified_loc.py


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