當前位置: 首頁>>代碼示例>>Python>>正文


Python pyplot.barh方法代碼示例

本文整理匯總了Python中matplotlib.pyplot.barh方法的典型用法代碼示例。如果您正苦於以下問題:Python pyplot.barh方法的具體用法?Python pyplot.barh怎麽用?Python pyplot.barh使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在matplotlib.pyplot的用法示例。


在下文中一共展示了pyplot.barh方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: plot_preds

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import barh [as 別名]
def plot_preds(image, preds):
    """Displays image and the top-n predicted probabilities in a bar graph
    Args:
        image: PIL image
        preds: list of predicted labels and their probabilities
    """
    
    """# For Spyder
    plt.imshow(image)
    plt.axis('off')"""

    plt.figure()
    labels = ("cat", "dog")
    plt.barh([0, 1], preds, alpha=0.5)
    plt.yticks([0, 1], labels)
    plt.xlabel('Probability')
    plt.xlim(0,1.01)
    plt.tight_layout()
    plt.savefig('out.png') 
開發者ID:DhavalThkkar,項目名稱:Transfer-Learning,代碼行數:21,代碼來源:predict.py

示例2: plot_bar_chart

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import barh [as 別名]
def plot_bar_chart(self, data):
        x = []
        y = []
        for item in data:
            y.append(item['count'])
            x.append(item['Implemented_by_partial_function'])
        plt.barh(x, y)
        plt.title("Top apis", fontsize=10)
        plt.xlabel("Number of API Calls", fontsize=8)
        plt.xticks([])
        plt.ylabel("Partial function", fontsize=8)
        plt.tick_params(axis='y', labelsize=8)
        for i, j in zip(y, x):
            plt.text(i, j, str(i), clip_on=True, ha='center',va='center', fontsize=8)
        plt.tight_layout()
        buf = BytesIO()
        plt.savefig(buf, format='png')
        image_base64 = base64.b64encode(buf.getvalue()).decode('utf-8').replace('\n', '')
        buf.close()
        # Clear the previous plot.
        plt.gcf().clear()
        return image_base64 
開發者ID:OpenBankProject,項目名稱:API-Manager,代碼行數:24,代碼來源:views.py

示例3: draw_one

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import barh [as 別名]
def draw_one(self, xls, title, color):
        title = '{} ({})'.format(title, xls.columns[0])
        column_a = xls[xls.columns[0]]
        column_c = xls[xls.columns[2]]

        ticks = [column_a[x] for x in range(3, 16)]
        kbps = [self.float2(column_c[x]) for x in range(3, 16)]
        plt.barh(range(16 - 3), kbps, height=0.2, color=color, alpha=0.8)
        plt.yticks(range(16 - 3), ticks)
        plt.xlim(0, max(kbps) * 1.2)
        plt.xlabel("Speed")
        plt.title(title)
        for x, y in enumerate(kbps):
            plt.text(y + 1000, x - 0.1, '%s KB/s' % y)

        plt.show() 
開發者ID:RainMark,項目名稱:oxfs,代碼行數:18,代碼來源:iozone_xls_to_graph.py

示例4: plot_topconsumer_bar_chart

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import barh [as 別名]
def plot_topconsumer_bar_chart(self, data):
        x = []
        y = []
        for item in data:
            y.append(item['count'])
            x.append(item['app_name'])
        plt.barh(x, y)
        plt.title("Top consumers", fontsize=10)
        plt.xlabel("Number of API Calls", fontsize=8)
        plt.xticks([])
        plt.ylabel("Consumers", fontsize=8)
        plt.tick_params(axis='y', labelsize=8)
        for i, j in zip(y, x):
            plt.text(i, j, str(i), clip_on=True, ha='center',va='center', fontsize=8)
        plt.tight_layout()
        buf = BytesIO()
        plt.savefig(buf, format='png')
        image_base64 = base64.b64encode(buf.getvalue()).decode('utf-8').replace('\n', '')
        buf.close()
        # Clear the previous plot.
        plt.gcf().clear()
        return image_base64 
開發者ID:OpenBankProject,項目名稱:API-Manager,代碼行數:24,代碼來源:views.py

示例5: plot_parameter_statistic

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import barh [as 別名]
def plot_parameter_statistic(model, layer_types=['Dense', 'Conv2D'], trainable=True, non_trainable=False, outputs=False):
    parameter_count = []
    names = []
    for l in model.layers:
        if l.__class__.__name__ not in layer_types:
            continue
        count = 0
        if outputs:
            count += np.sum([np.sum([np.prod(s[1:]) for s in n.output_shapes]) for n in l._inbound_nodes])
        if trainable:
            count += np.sum([K.count_params(p) for p in set(l.trainable_weights)])
        if non_trainable:
            count += np.sum([K.count_params(p) for p in set(l.non_trainable_weights)])
        parameter_count.append(count)
        names.append(l.name)
    
    y = range(len(names))
    plt.figure(figsize=[12,max(len(y)//4,1)])
    plt.barh(y, parameter_count, align='center')
    plt.yticks(y, names)
    plt.ylim(y[0]-1, y[-1]+1)
    ax = plt.gca()
    ax.invert_yaxis()
    ax.xaxis.tick_top()
    plt.show() 
開發者ID:mogoweb,項目名稱:aiexamples,代碼行數:27,代碼來源:model_utils.py

示例6: plot_dsc

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import barh [as 別名]
def plot_dsc(dsc_dist):
    y_positions = np.arange(len(dsc_dist))
    dsc_dist = sorted(dsc_dist.items(), key=lambda x: x[1])
    values = [x[1] for x in dsc_dist]
    labels = [x[0] for x in dsc_dist]
    labels = ["_".join(l.split("_")[1:-1]) for l in labels]
    fig = plt.figure(figsize=(12, 8))
    canvas = FigureCanvasAgg(fig)
    plt.barh(y_positions, values, align="center", color="skyblue")
    plt.yticks(y_positions, labels)
    plt.xticks(np.arange(0.0, 1.0, 0.1))
    plt.xlim([0.0, 1.0])
    plt.gca().axvline(np.mean(values), color="tomato", linewidth=2)
    plt.gca().axvline(np.median(values), color="forestgreen", linewidth=2)
    plt.xlabel("Dice coefficient", fontsize="x-large")
    plt.gca().xaxis.grid(color="silver", alpha=0.5, linestyle="--", linewidth=1)
    plt.tight_layout()
    canvas.draw()
    plt.close()
    s, (width, height) = canvas.print_to_buffer()
    return np.fromstring(s, np.uint8).reshape((height, width, 4)) 
開發者ID:mateuszbuda,項目名稱:brain-segmentation-pytorch,代碼行數:23,代碼來源:inference.py

示例7: render

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import barh [as 別名]
def render(self):
        """ Prepare data for plotting
        """

        # init figure
        self.fig, self.ax = plt.subplots()
        self.ax.yaxis.grid(False)
        self.ax.xaxis.grid(True)

        # assemble colors
        colors = []
        for pkg in self.packages:
            colors.append(pkg.color)

        self.barlist = plt.barh(self.yPos, list(self.durations),
                                left=self.start,
                                align='center',
                                height=.5,
                                alpha=1,
                                color=colors)

        # format plot
        self.format()
        self.add_milestones()
        self.add_legend() 
開發者ID:stefanSchinkel,項目名稱:gantt,代碼行數:27,代碼來源:gantt.py

示例8: altPlotFeaturesImportance

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import barh [as 別名]
def altPlotFeaturesImportance(X,y,featureNames,dataName):
    "http://nbviewer.ipython.org/github/cs109/2014/blob/master/homework-solutions/HW5-solutions.ipynb"
    clf = RandomForestClassifier(n_estimators=50)

    clf.fit(X,y)
    importance_list = clf.feature_importances_
    # name_list = df.columns #ORIG
    name_list=featureNames

    importance_list, name_list = zip(*sorted(zip(importance_list, name_list)))
    plt.barh(range(len(name_list)),importance_list,align='center')
    plt.yticks(range(len(name_list)),name_list)
    plt.xlabel('Relative Importance in the Random Forest')
    plt.ylabel('Features')
    plt.title('%s \n Relative Feature Importance' %(dataName))
    plt.grid('off')
    plt.ion()
    plt.show() 
開發者ID:ddofer,項目名稱:ProFET,代碼行數:20,代碼來源:VisualizeBestFeatures.py

示例9: draw_bar

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import barh [as 別名]
def draw_bar(labels,quants,indicate_path,xlabel,ylabel,title):
    width=0.35
    plt.figure(figsize=(8,(width+0.1)*len(quants)), dpi=300)
    # Bar Plot
    plt.cla()
    plt.clf()
    plt.barh(range(len(quants)),quants,tick_label=labels)
    plt.grid(True)
    plt.title(title)
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    plt.savefig(indicate_path)
    plt.close() 
開發者ID:kiharalab,項目名稱:DOVE,代碼行數:15,代碼來源:Show.py

示例10: generate_city_pic

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import barh [as 別名]
def generate_city_pic(self, city_data):
        """
        生成城市數據圖片
        因為plt在子線程中執行會出現自動彈出彈框並阻塞主線程的行為,plt行為均放在主線程中
        :param data:
        :return:
        """
        font = {'family': ['xkcd', 'Humor Sans', 'Comic Sans MS'],
                'weight': 'bold',
                'size': 12}
        matplotlib.rc('font', **font)
        cities = city_data['cities']
        city_people = city_data['city_people']

        # 繪製「性別分布」柱狀圖
        plt.barh(range(len(cities)), width=city_people, align='center', color=self.bar_color, alpha=0.8)
        # 添加軸標簽
        plt.xlabel(u'Number of People')
        # 添加標題
        plt.title(u'Top %d Cities of your friends distributed' % len(cities), fontsize=self.title_font_size)
        # 添加刻度標簽
        plt.yticks(range(len(cities)), cities)
        # 設置X軸的刻度範圍
        plt.xlim([0, city_people[0] * 1.1])

        # 為每個條形圖添加數值標簽
        for x, y in enumerate(city_people):
            plt.text(y + len(str(y)), x, y, ha='center')

        # 顯示圖形
        plt.savefig(ALS.result_path + '/4.png')
        # todo 如果調用此處的關閉,就會導致應用本身也被關閉
        # plt.close()
        # plt.show() 
開發者ID:newbietian,項目名稱:WxConn,代碼行數:36,代碼來源:main.py

示例11: draw_compare

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import barh [as 別名]
def draw_compare(self):
        xls = self.oxfs_xls
        column_a = xls[xls.columns[0]]
        column_c = xls[xls.columns[2]]

        oxfs_ticks = [column_a[x] + '- oxfs' for x in range(3, 16)]
        oxfs_kbps = [self.float2(column_c[x]) for x in range(3, 16)]

        xls = self.sshfs_xls
        column_a = xls[xls.columns[0]]
        column_c = xls[xls.columns[2]]

        sshfs_ticks = [column_a[x] + '- sshfs' for x in range(3, 16)]
        sshfs_kbps = [self.float2(column_c[x]) for x in range(3, 16)]

        ticks = []
        kbps = []
        for i in range(0, len(oxfs_kbps)):
            ticks.append(oxfs_ticks[i])
            ticks.append(sshfs_ticks[i])
            kbps.append(oxfs_kbps[i])
            kbps.append(sshfs_kbps[i])

        barlist = plt.barh(range(len(kbps)), kbps, height=0.3, color='coral', alpha=0.8)
        for bar in barlist[1::2]:
            bar.set_color('slateblue')
        plt.yticks(range(len(ticks)), ticks)
        plt.xlim(0, max(kbps) * 1.2)
        for x, y in enumerate(kbps):
            plt.text(y + 1000, x - 0.1, '%s KB/s' % y)

        title = 'Oxfs Vs Sshfs ({})'.format(xls.columns[0])
        plt.title(title)
        plt.xlabel("Speed")

        plt.show() 
開發者ID:RainMark,項目名稱:oxfs,代碼行數:38,代碼來源:iozone_xls_to_graph.py

示例12: plot_performance

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import barh [as 別名]
def plot_performance(perf, kmax = 100, prec_type = 'LCS_HEIGHT', clip_ahp = None):
    
    import matplotlib.pyplot as plt
    
    plt.figure()
    plt.xlabel('k')
    plt.ylabel('Hierarchical Precision')
    plt.xlim(0, kmax)
    plt.ylim(0, 1)
    plt.grid()
    
    min_prec = 1.0
    for lbl, metrics in perf.items():
        precs = [metrics['P@{} ({})'.format(k, prec_type)] for k in range(1, kmax+1)]
        plt.plot(np.arange(1, kmax + 1), precs, label = lbl)
        min_prec = min(min_prec, min(precs))
    
    min_prec = np.floor(min_prec * 20) / 20
    if min_prec >= 0.3:
        plt.ylim(min_prec, 1)
    
    plt.legend(fontsize = 'x-small')
    
    
    plt.figure()
    plt.xlabel('Mean Average Hierarchical Precision')
    plt.yticks([])
    plt.grid(axis = 'x')
    
    for i, (lbl, metrics) in enumerate(perf.items()):
        mAHP = metrics['AHP{} ({})'.format('@{}'.format(clip_ahp) if clip_ahp else '', prec_type)]
        plt.barh(i + 0.5, mAHP, 0.8)
        plt.text(0.01, i + 0.5, lbl, verticalalignment = 'center', horizontalalignment = 'left', color = 'white', fontsize = 'small')
        plt.text(mAHP - 0.01, i + 0.5, '{:.1%}'.format(mAHP), verticalalignment = 'center', horizontalalignment = 'right', color = 'white')
    
    
    plt.show() 
開發者ID:cvjena,項目名稱:semantic-embeddings,代碼行數:39,代碼來源:evaluate_retrieval.py

示例13: barHonGraphics

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import barh [as 別名]
def barHonGraphics(xLabel,yLabel,xValueList,yValueList,graphicTitle='圖例',xWidth=0.5):
    plt.barh(numpy.arange(len(xValueList)), yValueList, alpha=0.4)
    plt.yticks(numpy.arange(len(xValueList)), xValueList,fontproperties=font_set)
    plt.xlabel(yLabel,fontproperties=font_set)
    plt.ylabel(xLabel,fontproperties=font_set)
    plt.title(graphicTitle,fontproperties=font_set)

    plt.show()
	
#折線圖:藍色粗線 
開發者ID:ankanch,項目名稱:tieba-zhuaqu,代碼行數:12,代碼來源:graphicsData.py

示例14: plot_feature_split_proportions

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import barh [as 別名]
def plot_feature_split_proportions(model: SklearnModel, ax=None):
    if ax is None:
        _, ax = plt.subplots(1, 1)
    proportions = feature_split_proportions(model)

    y_pos = np.arange(len(proportions))
    name, count = list(proportions.keys()), list(proportions.values())
    props = pd.DataFrame({"name": name, "counts": count}).sort_values("name", ascending=True)
    plt.barh(y_pos, props.counts, align='center', alpha=0.5)
    plt.yticks(y_pos, props.name)
    plt.xlabel('Proportion of all splits')
    plt.ylabel('Feature')
    plt.title('Proportion of Splits Made on Each Variable')
    return ax 
開發者ID:JakeColtman,項目名稱:bartpy,代碼行數:16,代碼來源:features.py

示例15: plot

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import barh [as 別名]
def plot(counts):
    labels = map(lambda x: x[0], counts)
    values = map(lambda y: y[1], counts)
    plt.barh(range(len(values)), values, color='green')
    plt.yticks(range(len(values)), labels)
    plt.show() 
開發者ID:PacktPublishing,項目名稱:big-data-analytics,代碼行數:8,代碼來源:JupyterNotebook.py


注:本文中的matplotlib.pyplot.barh方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。