本文整理匯總了Python中matplotlib.colors.BASE_COLORS屬性的典型用法代碼示例。如果您正苦於以下問題:Python colors.BASE_COLORS屬性的具體用法?Python colors.BASE_COLORS怎麽用?Python colors.BASE_COLORS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類matplotlib.colors
的用法示例。
在下文中一共展示了colors.BASE_COLORS屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: att_plot
# 需要導入模塊: from matplotlib import colors [as 別名]
# 或者: from matplotlib.colors import BASE_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')
示例2: draw_embedding
# 需要導入模塊: from matplotlib import colors [as 別名]
# 或者: from matplotlib.colors import BASE_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()