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


Python colors.CSS4_COLORS属性代码示例

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


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

示例1: att_plot

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import CSS4_COLORS [as 别名]
def att_plot(top_labels, gt_ind, probs, fn):
    # plt.figure(figsize=(5, 5))
    #
    # color_dict = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS)
    # colors = [color_dict[c] for c in
    #           ['lightcoral', 'steelblue', 'forestgreen', 'darkviolet', 'sienna', 'dimgrey',
    #            'darkorange', 'gold']]
    # colors[gt_ind] = color_dict['crimson']
    # w = 0.9
    # plt.bar(np.arange(len(top_labels)), probs, w, color=colors, alpha=.9, label='data')
    # plt.axhline(0, color='black')
    # plt.ylim([0, 1])
    # plt.xticks(np.arange(len(top_labels)), top_labels, fontsize=6)
    # plt.subplots_adjust(bottom=.15)
    # plt.tight_layout()
    # plt.savefig(fn)
    lab = deepcopy(top_labels)
    lab[gt_ind] += ' (gt)'
    d = pd.DataFrame(data={'probs': probs, 'labels':lab})
    fig, ax = plt.subplots(figsize=(4,5))
    ax.tick_params(labelsize=15)

    sns.barplot(y='labels', x='probs', ax=ax, data=d, orient='h', ci=None)
    ax.set(xlim=(0,1))

    for rect, label in zip(ax.patches,lab):
        w = rect.get_width()
        ax.text(w+.02, rect.get_y() + rect.get_height()*4/5, label, ha='left', va='bottom',
                fontsize=25)

    # ax.yaxis.set_label_coords(0.5, 0.5)
    ax.spines['right'].set_visible(False)
    ax.spines['top'].set_visible(False)
    ax.get_yaxis().set_visible(False)
    ax.get_xaxis().label.set_visible(False)
    fig.savefig(fn, bbox_inches='tight', transparent=True)
    plt.close('all') 
开发者ID:uwnlp,项目名称:verb-attributes,代码行数:39,代码来源:fig_4.py

示例2: draw_embedding

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import CSS4_COLORS [as 别名]
def draw_embedding(embs, names, resultpath, algos, show_label):
        """Function to draw the embedding.

            Args:
                embs (matrix): Two dimesnional embeddings.
                names (list):List of string name.
                resultpath (str):Path where the result will be save.
                algos (str): Name of the algorithms which generated the algorithm.
                show_label (bool): If True, prints the string names of the entities and relations.

        """
        pos = {}
        node_color_mp = {}
        unique_ent = set(names)
        colors = list(dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS).keys())

        tot_col = len(colors)
        j = 0
        for i, e in enumerate(unique_ent):
            node_color_mp[e] = colors[j]
            j += 1
            if j >= tot_col:
                j = 0

        G = nx.Graph()
        hm_ent = {}
        for i, ent in enumerate(names):
            hm_ent[i] = ent
            G.add_node(i)
            pos[i] = embs[i]

        colors = []
        for n in list(G.nodes):
            colors.append(node_color_mp[hm_ent[n]])

        plt.figure()
        nodes_draw = nx.draw_networkx_nodes(G,
                                            pos,
                                            node_color=colors,
                                            node_size=50)
        nodes_draw.set_edgecolor('k')
        if show_label:
            nx.draw_networkx_labels(G, pos, font_size=8)

        if not os.path.exists(resultpath):
            os.mkdir(resultpath)

        files = os.listdir(resultpath)
        file_no = len(
            [c for c in files if algos + '_embedding_plot' in c])
        filename = algos + '_embedding_plot_' + str(file_no) + '.png'
        plt.savefig(str(resultpath / filename), bbox_inches='tight', dpi=300)
        # plt.show() 
开发者ID:Sujit-O,项目名称:pykg2vec,代码行数:55,代码来源:visualization.py


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