本文整理汇总了Python中matplotlib.colors.Normalize.clip方法的典型用法代码示例。如果您正苦于以下问题:Python Normalize.clip方法的具体用法?Python Normalize.clip怎么用?Python Normalize.clip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.colors.Normalize
的用法示例。
在下文中一共展示了Normalize.clip方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: visualize_temporal_activities
# 需要导入模块: from matplotlib.colors import Normalize [as 别名]
# 或者: from matplotlib.colors.Normalize import clip [as 别名]
def visualize_temporal_activities(class_predictions, max_value=200, fps=1, title=None, legend=False):
normalize = Normalize(vmin=1, vmax=max_value)
normalize.clip=False
cmap = plt.cm.Reds
cmap.set_under('w')
nb_instances = len(class_predictions)
plt.figure(num=None, figsize=(18, 1), dpi=100)
to_plot = class_predictions.astype(np.float32)
to_plot[class_predictions==0.] = np.ma.masked
plt.imshow(np.broadcast_to(to_plot, (20, nb_instances)), norm=normalize, interpolation='nearest', aspect='auto', cmap=cmap)
if title:
plt.title(title)
ax = plt.gca()
ax.get_yaxis().set_visible(False)
if legend:
index = np.arange(0,200)
colors_index = np.unique(to_plot).astype(np.int64)
if 0 in colors_index:
colors_index = np.delete(colors_index, 0)
patches = []
for c in colors_index:
patches.append(mpatches.Patch(color=cmap(normalize(c)), label=dataset.labels[c][1]))
if patches:
plt.legend(handles=patches, loc='upper center', bbox_to_anchor=(0.5, -.2), ncol=len(patches), fancybox=True, shadow=True)
plt.show()
示例2: compare_temporal_activities
# 需要导入模块: from matplotlib.colors import Normalize [as 别名]
# 或者: from matplotlib.colors.Normalize import clip [as 别名]
def compare_temporal_activities(ground_truth, class_predictions, max_value=200, fps=1, title=None, legend=False, save_file='./img/activity_detection_sample_{}.png'):
global count
normalize = Normalize(vmin=1, vmax=max_value)
normalize.clip=False
cmap = plt.cm.Reds
cmap.set_under('w')
nb_instances = len(class_predictions)
to_plot = np.zeros((20, nb_instances))
to_plot[:10,:] = np.broadcast_to(ground_truth, (10, nb_instances))
to_plot[10:,:] = np.broadcast_to(class_predictions, (10, nb_instances))
to_plot = to_plot.astype(np.float32)
to_plot[to_plot==0.] = np.ma.masked
# Normalize the values and give them the largest distance possible between them
unique_values = np.unique(to_plot).astype(np.int64)
if 0 in unique_values:
unique_values = np.delete(unique_values, 0)
nb_different_values = len(unique_values)
color_values = np.linspace(40, 190, nb_different_values)
for i in range(nb_different_values):
to_plot[to_plot == unique_values[i]] = color_values[i]
plt.figure(num=None, figsize=(18, 1), dpi=100)
plt.imshow(to_plot, norm=normalize, interpolation='nearest', aspect='auto', cmap=cmap)
#plt.grid(True)
plt.axhline(9, linestyle='-', color='k')
plt.xlim([0,nb_instances])
if title:
plt.title(title)
ax = plt.gca()
#ax.get_yaxis().set_visible(False)
ax.xaxis.grid(True, which='major')
labels=['Ground\nTruth', 'Prediction']
plt.yticks([5,15], labels, rotation="horizontal", size=13)
plt.xlabel('Time (s)', horizontalalignment='left', fontsize=13)
ax.xaxis.set_label_coords(0, -0.3)
if legend:
patches = []
for c, l in zip(color_values, unique_values):
patches.append(mpatches.Patch(color=cmap(normalize(c)), label=dataset.labels[l][1]))
if patches:
plt.legend(handles=patches, loc='upper center', bbox_to_anchor=(.5, -.2), ncol=len(patches), fancybox=True, shadow=True)
#plt.show()
plt.savefig(save_file.format(count), bbox_inches='tight')
count += 1