當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。