Python matplotlib.patheffects.Stroke() Examples
The following are 30
code examples of matplotlib.patheffects.Stroke().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.patheffects
, or try the search function
.
Example #1
Source File: test_patheffects.py From neural-network-animation with MIT License | 8 votes |
def test_collection(): x, y = np.meshgrid(np.linspace(0, 10, 150), np.linspace(-5, 5, 100)) data = np.sin(x) + np.cos(y) cs = plt.contour(data) pe = [path_effects.PathPatchEffect(edgecolor='black', facecolor='none', linewidth=12), path_effects.Stroke(linewidth=5)] for collection in cs.collections: collection.set_path_effects(pe) for text in plt.clabel(cs, colors='white'): text.set_path_effects([path_effects.withStroke(foreground='k', linewidth=3)]) text.set_bbox({'boxstyle': 'sawtooth', 'facecolor': 'none', 'edgecolor': 'blue'})
Example #2
Source File: test_patheffects.py From ImageFusion with MIT License | 6 votes |
def test_patheffect3(): p1, = plt.plot([1, 3, 5, 4, 3], 'o-b', lw=4) p1.set_path_effects([path_effects.SimpleLineShadow(), path_effects.Normal()]) plt.title(r'testing$^{123}$', path_effects=[path_effects.withStroke(linewidth=1, foreground="r")]) leg = plt.legend([p1], [r'Line 1$^2$'], fancybox=True, loc=2) leg.legendPatch.set_path_effects([path_effects.withSimplePatchShadow()]) text = plt.text(2, 3, 'Drop test', color='white', bbox={'boxstyle': 'circle,pad=0.1', 'color': 'red'}) pe = [path_effects.Stroke(linewidth=3.75, foreground='k'), path_effects.withSimplePatchShadow((6, -3), shadow_rgbFace='blue')] text.set_path_effects(pe) text.get_bbox_patch().set_path_effects(pe) pe = [path_effects.PathPatchEffect(offset=(4, -4), hatch='xxxx', facecolor='gray'), path_effects.PathPatchEffect(edgecolor='white', facecolor='black', lw=1.1)] t = plt.gcf().text(0.02, 0.1, 'Hatch shadow', fontsize=75, weight=1000, va='center') t.set_path_effects(pe)
Example #3
Source File: test_patheffects.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_collection(): x, y = np.meshgrid(np.linspace(0, 10, 150), np.linspace(-5, 5, 100)) data = np.sin(x) + np.cos(y) cs = plt.contour(data) pe = [path_effects.PathPatchEffect(edgecolor='black', facecolor='none', linewidth=12), path_effects.Stroke(linewidth=5)] for collection in cs.collections: collection.set_path_effects(pe) for text in plt.clabel(cs, colors='white'): text.set_path_effects([path_effects.withStroke(foreground='k', linewidth=3)]) text.set_bbox({'boxstyle': 'sawtooth', 'facecolor': 'none', 'edgecolor': 'blue'})
Example #4
Source File: test_patheffects.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_patheffects_stroked_text(): text_chunks = [ 'A B C D E F G H I J K L', 'M N O P Q R S T U V W', 'X Y Z a b c d e f g h i j', 'k l m n o p q r s t u v', 'w x y z 0123456789', r"!@#$%^&*()-=_+[]\;'", ',./{}|:"<>?' ] font_size = 50 ax = plt.axes([0, 0, 1, 1]) for i, chunk in enumerate(text_chunks): text = ax.text(x=0.01, y=(0.9 - i * 0.13), s=chunk, fontdict={'ha': 'left', 'va': 'center', 'size': font_size, 'color': 'white'}) text.set_path_effects([path_effects.Stroke(linewidth=font_size / 10, foreground='black'), path_effects.Normal()]) ax.set_xlim(0, 1) ax.set_ylim(0, 1) ax.axis('off')
Example #5
Source File: test_patheffects.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_patheffect3(): p1, = plt.plot([1, 3, 5, 4, 3], 'o-b', lw=4) p1.set_path_effects([path_effects.SimpleLineShadow(), path_effects.Normal()]) plt.title(r'testing$^{123}$', path_effects=[path_effects.withStroke(linewidth=1, foreground="r")]) leg = plt.legend([p1], [r'Line 1$^2$'], fancybox=True, loc=2) leg.legendPatch.set_path_effects([path_effects.withSimplePatchShadow()]) text = plt.text(2, 3, 'Drop test', color='white', bbox={'boxstyle': 'circle,pad=0.1', 'color': 'red'}) pe = [path_effects.Stroke(linewidth=3.75, foreground='k'), path_effects.withSimplePatchShadow((6, -3), shadow_rgbFace='blue')] text.set_path_effects(pe) text.get_bbox_patch().set_path_effects(pe) pe = [path_effects.PathPatchEffect(offset=(4, -4), hatch='xxxx', facecolor='gray'), path_effects.PathPatchEffect(edgecolor='white', facecolor='black', lw=1.1)] t = plt.gcf().text(0.02, 0.1, 'Hatch shadow', fontsize=75, weight=1000, va='center') t.set_path_effects(pe)
Example #6
Source File: test_patheffects.py From coffeegrindsize with MIT License | 6 votes |
def test_collection(): x, y = np.meshgrid(np.linspace(0, 10, 150), np.linspace(-5, 5, 100)) data = np.sin(x) + np.cos(y) cs = plt.contour(data) pe = [path_effects.PathPatchEffect(edgecolor='black', facecolor='none', linewidth=12), path_effects.Stroke(linewidth=5)] for collection in cs.collections: collection.set_path_effects(pe) for text in plt.clabel(cs, colors='white'): text.set_path_effects([path_effects.withStroke(foreground='k', linewidth=3)]) text.set_bbox({'boxstyle': 'sawtooth', 'facecolor': 'none', 'edgecolor': 'blue'})
Example #7
Source File: test_patheffects.py From coffeegrindsize with MIT License | 6 votes |
def test_patheffects_stroked_text(): text_chunks = [ 'A B C D E F G H I J K L', 'M N O P Q R S T U V W', 'X Y Z a b c d e f g h i j', 'k l m n o p q r s t u v', 'w x y z 0123456789', r"!@#$%^&*()-=_+[]\;'", ',./{}|:"<>?' ] font_size = 50 ax = plt.axes([0, 0, 1, 1]) for i, chunk in enumerate(text_chunks): text = ax.text(x=0.01, y=(0.9 - i * 0.13), s=chunk, fontdict={'ha': 'left', 'va': 'center', 'size': font_size, 'color': 'white'}) text.set_path_effects([path_effects.Stroke(linewidth=font_size / 10, foreground='black'), path_effects.Normal()]) ax.set_xlim(0, 1) ax.set_ylim(0, 1) ax.axis('off')
Example #8
Source File: test_patheffects.py From coffeegrindsize with MIT License | 6 votes |
def test_patheffect3(): p1, = plt.plot([1, 3, 5, 4, 3], 'o-b', lw=4) p1.set_path_effects([path_effects.SimpleLineShadow(), path_effects.Normal()]) plt.title(r'testing$^{123}$', path_effects=[path_effects.withStroke(linewidth=1, foreground="r")]) leg = plt.legend([p1], [r'Line 1$^2$'], fancybox=True, loc='upper left') leg.legendPatch.set_path_effects([path_effects.withSimplePatchShadow()]) text = plt.text(2, 3, 'Drop test', color='white', bbox={'boxstyle': 'circle,pad=0.1', 'color': 'red'}) pe = [path_effects.Stroke(linewidth=3.75, foreground='k'), path_effects.withSimplePatchShadow((6, -3), shadow_rgbFace='blue')] text.set_path_effects(pe) text.get_bbox_patch().set_path_effects(pe) pe = [path_effects.PathPatchEffect(offset=(4, -4), hatch='xxxx', facecolor='gray'), path_effects.PathPatchEffect(edgecolor='white', facecolor='black', lw=1.1)] t = plt.gcf().text(0.02, 0.1, 'Hatch shadow', fontsize=75, weight=1000, va='center') t.set_path_effects(pe)
Example #9
Source File: utils.py From gluon-face with MIT License | 6 votes |
def plot_result(embeds, labels, output_path): # vis, plot code from https://github.com/pangyupo/mxnet_center_loss num = len(labels) names = dict() for i in range(10): names[i] = str(i) palette = np.array(sns.color_palette("hls", 10)) f = plt.figure(figsize=(8, 8)) ax = plt.subplot(aspect='equal') sc = ax.scatter(embeds[:, 0], embeds[:, 1], lw=0, s=40, c=palette[labels.astype(np.int)]) ax.axis('off') ax.axis('tight') # We add the labels for each digit. txts = [] for i in range(10): # Position of each label. xtext, ytext = np.median(embeds[labels == i, :], axis=0) txt = ax.text(xtext, ytext, names[i]) txt.set_path_effects([ PathEffects.Stroke(linewidth=5, foreground="w"), PathEffects.Normal()]) txts.append(txt) plt.savefig(output_path)
Example #10
Source File: test_patheffects.py From ImageFusion with MIT License | 6 votes |
def test_collection(): x, y = np.meshgrid(np.linspace(0, 10, 150), np.linspace(-5, 5, 100)) data = np.sin(x) + np.cos(y) cs = plt.contour(data) pe = [path_effects.PathPatchEffect(edgecolor='black', facecolor='none', linewidth=12), path_effects.Stroke(linewidth=5)] for collection in cs.collections: collection.set_path_effects(pe) for text in plt.clabel(cs, colors='white'): text.set_path_effects([path_effects.withStroke(foreground='k', linewidth=3)]) text.set_bbox({'boxstyle': 'sawtooth', 'facecolor': 'none', 'edgecolor': 'blue'})
Example #11
Source File: test_patheffects.py From ImageFusion with MIT License | 6 votes |
def test_patheffect1(): ax1 = plt.subplot(111) ax1.imshow([[1, 2], [2, 3]]) txt = ax1.annotate("test", (1., 1.), (0., 0), arrowprops=dict(arrowstyle="->", connectionstyle="angle3", lw=2), size=20, ha="center", path_effects=[path_effects.withStroke(linewidth=3, foreground="w")]) txt.arrow_patch.set_path_effects([path_effects.Stroke(linewidth=5, foreground="w"), path_effects.Normal()]) ax1.grid(True, linestyle="-") pe = [path_effects.withStroke(linewidth=3, foreground="w")] for l in ax1.get_xgridlines() + ax1.get_ygridlines(): l.set_path_effects(pe)
Example #12
Source File: analyse_results.py From YAFS with MIT License | 6 votes |
def drawRequestOnTimeline(ticks,messagesbyTime,i=0): fig, ax = plt.subplots(figsize=(8.0,4.0)) ax.plot(ticks, messagesbyTime, '-',color='#756bb1',alpha=1.,linewidth=2) z = np.polyfit(ticks, messagesbyTime, 10) p = np.poly1d(z) ax1 = ax.plot(ticks,p(ticks),":",color='#c1bcdc',linewidth=6,label="Total num. of requests",path_effects=[pe.Stroke(linewidth=8, foreground='purple'), pe.Normal()]) ax.set_xlabel("Simulation number: %i"%i, fontsize=12) ax.set_ylabel("QoS satisfaction \n (num. of requests)", fontsize=12) ax.tick_params(labelsize=10) #ax.set_xlim(-20,2020) #ax.set_ylim(0,120) #plt.legend([ax1,ax2,ax3],['Total num. of requests','Partition','ILP'],loc="upper right",fontsize=18) plt.legend(loc="lower left",fontsize=12) plt.tight_layout() #plt.savefig('TimeSerie_Requests-%i.pdf'%i, format='pdf', dpi=600)
Example #13
Source File: analyse_results_paper_v2.py From YAFS with MIT License | 6 votes |
def drawRequestOnTimeline(ticks,messagesbyTime,i=0): fig, ax = plt.subplots(figsize=(8.0,4.0)) ax.plot(ticks, messagesbyTime, '-',color='#756bb1',alpha=1.,linewidth=2) z = np.polyfit(ticks, messagesbyTime, 10) p = np.poly1d(z) ax1 = ax.plot(ticks,p(ticks),":",color='#c1bcdc',linewidth=6,label="Total num. of requests",path_effects=[pe.Stroke(linewidth=8, foreground='purple'), pe.Normal()]) ax.set_xlabel("Simulation number: %i"%i, fontsize=12) ax.set_ylabel("QoS satisfaction \n (num. of requests)", fontsize=12) ax.tick_params(labelsize=10) #ax.set_xlim(-20,2020) #ax.set_ylim(0,120) #plt.legend([ax1,ax2,ax3],['Total num. of requests','Partition','ILP'],loc="upper right",fontsize=18) plt.legend(loc="lower left",fontsize=12) plt.tight_layout() #plt.savefig('TimeSerie_Requests-%i.pdf'%i, format='pdf', dpi=600)
Example #14
Source File: test_patheffects.py From neural-network-animation with MIT License | 6 votes |
def test_patheffect1(): ax1 = plt.subplot(111) ax1.imshow([[1, 2], [2, 3]]) txt = ax1.annotate("test", (1., 1.), (0., 0), arrowprops=dict(arrowstyle="->", connectionstyle="angle3", lw=2), size=20, ha="center", path_effects=[path_effects.withStroke(linewidth=3, foreground="w")]) txt.arrow_patch.set_path_effects([path_effects.Stroke(linewidth=5, foreground="w"), path_effects.Normal()]) ax1.grid(True, linestyle="-") pe = [path_effects.withStroke(linewidth=3, foreground="w")] for l in ax1.get_xgridlines() + ax1.get_ygridlines(): l.set_path_effects(pe)
Example #15
Source File: test_patheffects.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_collection(): x, y = np.meshgrid(np.linspace(0, 10, 150), np.linspace(-5, 5, 100)) data = np.sin(x) + np.cos(y) cs = plt.contour(data) pe = [path_effects.PathPatchEffect(edgecolor='black', facecolor='none', linewidth=12), path_effects.Stroke(linewidth=5)] for collection in cs.collections: collection.set_path_effects(pe) for text in plt.clabel(cs, colors='white'): text.set_path_effects([path_effects.withStroke(foreground='k', linewidth=3)]) text.set_bbox({'boxstyle': 'sawtooth', 'facecolor': 'none', 'edgecolor': 'blue'})
Example #16
Source File: test_patheffects.py From neural-network-animation with MIT License | 6 votes |
def test_patheffect3(): p1, = plt.plot([1, 3, 5, 4, 3], 'o-b', lw=4) p1.set_path_effects([path_effects.SimpleLineShadow(), path_effects.Normal()]) plt.title(r'testing$^{123}$', path_effects=[path_effects.withStroke(linewidth=1, foreground="r")]) leg = plt.legend([p1], [r'Line 1$^2$'], fancybox=True, loc=2) leg.legendPatch.set_path_effects([path_effects.withSimplePatchShadow()]) text = plt.text(2, 3, 'Drop test', color='white', bbox={'boxstyle': 'circle,pad=0.1', 'color': 'red'}) pe = [path_effects.Stroke(linewidth=3.75, foreground='k'), path_effects.withSimplePatchShadow((6, -3), shadow_rgbFace='blue')] text.set_path_effects(pe) text.get_bbox_patch().set_path_effects(pe) pe = [path_effects.PathPatchEffect(offset=(4, -4), hatch='xxxx', facecolor='gray'), path_effects.PathPatchEffect(edgecolor='white', facecolor='black', lw=1.1)] t = plt.gcf().text(0.02, 0.1, 'Hatch shadow', fontsize=75, weight=1000, va='center') t.set_path_effects(pe)
Example #17
Source File: test_patheffects.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_patheffects_stroked_text(): text_chunks = [ 'A B C D E F G H I J K L', 'M N O P Q R S T U V W', 'X Y Z a b c d e f g h i j', 'k l m n o p q r s t u v', 'w x y z 0123456789', r"!@#$%^&*()-=_+[]\;'", ',./{}|:"<>?' ] font_size = 50 ax = plt.axes([0, 0, 1, 1]) for i, chunk in enumerate(text_chunks): text = ax.text(x=0.01, y=(0.9 - i * 0.13), s=chunk, fontdict={'ha': 'left', 'va': 'center', 'size': font_size, 'color': 'white'}) text.set_path_effects([path_effects.Stroke(linewidth=font_size / 10, foreground='black'), path_effects.Normal()]) ax.set_xlim(0, 1) ax.set_ylim(0, 1) ax.axis('off')
Example #18
Source File: analyse_results_paper.py From YAFS with MIT License | 6 votes |
def drawRequestOnTimeline(ticks,messagesbyTime,i=0): fig, ax = plt.subplots(figsize=(8.0,4.0)) ax.plot(ticks, messagesbyTime, '-',color='#756bb1',alpha=1.,linewidth=2) z = np.polyfit(ticks, messagesbyTime, 10) p = np.poly1d(z) ax1 = ax.plot(ticks,p(ticks),":",color='#c1bcdc',linewidth=6,label="Total num. of requests",path_effects=[pe.Stroke(linewidth=8, foreground='purple'), pe.Normal()]) ax.set_xlabel("Simulation number: %i"%i, fontsize=12) ax.set_ylabel("QoS satisfaction \n (num. of requests)", fontsize=12) ax.tick_params(labelsize=10) #ax.set_xlim(-20,2020) #ax.set_ylim(0,120) #plt.legend([ax1,ax2,ax3],['Total num. of requests','Partition','ILP'],loc="upper right",fontsize=18) plt.legend(loc="lower left",fontsize=12) plt.tight_layout() #plt.savefig('TimeSerie_Requests-%i.pdf'%i, format='pdf', dpi=600)
Example #19
Source File: test_patheffects.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_patheffect3(): p1, = plt.plot([1, 3, 5, 4, 3], 'o-b', lw=4) p1.set_path_effects([path_effects.SimpleLineShadow(), path_effects.Normal()]) plt.title(r'testing$^{123}$', path_effects=[path_effects.withStroke(linewidth=1, foreground="r")]) leg = plt.legend([p1], [r'Line 1$^2$'], fancybox=True, loc='upper left') leg.legendPatch.set_path_effects([path_effects.withSimplePatchShadow()]) text = plt.text(2, 3, 'Drop test', color='white', bbox={'boxstyle': 'circle,pad=0.1', 'color': 'red'}) pe = [path_effects.Stroke(linewidth=3.75, foreground='k'), path_effects.withSimplePatchShadow((6, -3), shadow_rgbFace='blue')] text.set_path_effects(pe) text.get_bbox_patch().set_path_effects(pe) pe = [path_effects.PathPatchEffect(offset=(4, -4), hatch='xxxx', facecolor='gray'), path_effects.PathPatchEffect(edgecolor='white', facecolor='black', lw=1.1)] t = plt.gcf().text(0.02, 0.1, 'Hatch shadow', fontsize=75, weight=1000, va='center') t.set_path_effects(pe)
Example #20
Source File: test_patheffects.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_patheffect1(): ax1 = plt.subplot(111) ax1.imshow([[1, 2], [2, 3]]) txt = ax1.annotate("test", (1., 1.), (0., 0), arrowprops=dict(arrowstyle="->", connectionstyle="angle3", lw=2), size=20, ha="center", path_effects=[path_effects.withStroke(linewidth=3, foreground="w")]) txt.arrow_patch.set_path_effects([path_effects.Stroke(linewidth=5, foreground="w"), path_effects.Normal()]) pe = [path_effects.withStroke(linewidth=3, foreground="w")] ax1.grid(True, linestyle="-", path_effects=pe)
Example #21
Source File: pico_viz_robot.py From robotreviewer with GNU General Public License v3.0 | 5 votes |
def scatter(study_names, X, ax, title="population", norm=False): n_studies = X.shape[0] palette = np.array(sns.color_palette("hls", n_studies)) sc = ax.scatter(X[:,0], X[:,1], lw=0, s=60, c=palette[np.arange(n_studies)]) # add labels for each study txts = [] X_range = X[:,0].max()-X[:,0].min() Y_range = X[:,1].max()-X[:,1].min() for i in range(n_studies): # note that the below magic numbers are for aesthetics # only and are simply based on (manual) fiddling! jitter = np.array([-.05*X_range, .03*Y_range]) xtext, ytext = X[i, :] + jitter txt = ax.text(xtext, ytext, study_names[i], fontsize=9) txt.set_path_effects([PathEffects.Stroke(linewidth=5, foreground="w"), PathEffects.Normal()]) txts.append(txt) ax.set_xlim(min(X[:,0])-.5*X_range, max(X[:,0])+.5*X_range) ax.set_ylim(min(X[:,1])-.1*Y_range, max(X[:,1])+.1*Y_range) ax.set_title(title) ax.set_xticks([]) ax.set_yticks([]) ax.axis('off') # also return palette for later use return sc, convert_to_RGB(palette[np.arange(n_studies)])
Example #22
Source File: test_patheffects.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_patheffect1(): ax1 = plt.subplot(111) ax1.imshow([[1, 2], [2, 3]]) txt = ax1.annotate("test", (1., 1.), (0., 0), arrowprops=dict(arrowstyle="->", connectionstyle="angle3", lw=2), size=20, ha="center", path_effects=[path_effects.withStroke(linewidth=3, foreground="w")]) txt.arrow_patch.set_path_effects([path_effects.Stroke(linewidth=5, foreground="w"), path_effects.Normal()]) pe = [path_effects.withStroke(linewidth=3, foreground="w")] ax1.grid(True, linestyle="-", path_effects=pe)
Example #23
Source File: tools.py From tropycal with MIT License | 5 votes |
def add_credit(ax,text): import matplotlib.patheffects as path_effects a = ax.text(0.99,0.01,text,fontsize=9,color='k',alpha=0.7,fontweight='bold', transform=ax.transAxes,ha='right',va='bottom',zorder=10) a.set_path_effects([path_effects.Stroke(linewidth=5, foreground='white'), path_effects.Normal()])
Example #24
Source File: plot.py From tropycal with MIT License | 5 votes |
def add_credit(self,text): if self.use_credit: a = self.ax.text(0.99,0.01,text,fontsize=10,color='k',alpha=0.7,fontweight='bold', transform=self.ax.transAxes,ha='right',va='bottom',zorder=10) a.set_path_effects([path_effects.Stroke(linewidth=5, foreground='white'), path_effects.Normal()])
Example #25
Source File: test_patheffects.py From coffeegrindsize with MIT License | 5 votes |
def test_patheffect1(): ax1 = plt.subplot(111) ax1.imshow([[1, 2], [2, 3]]) txt = ax1.annotate("test", (1., 1.), (0., 0), arrowprops=dict(arrowstyle="->", connectionstyle="angle3", lw=2), size=20, ha="center", path_effects=[path_effects.withStroke(linewidth=3, foreground="w")]) txt.arrow_patch.set_path_effects([path_effects.Stroke(linewidth=5, foreground="w"), path_effects.Normal()]) pe = [path_effects.withStroke(linewidth=3, foreground="w")] ax1.grid(True, linestyle="-", path_effects=pe)
Example #26
Source File: utils.py From dynamo-release with BSD 3-Clause "New" or "Revised" License | 5 votes |
def scatter_with_legend( fig, ax, df, font_color, x, y, c, cmap, legend, **scatter_kwargs ): import seaborn as sns import matplotlib.patheffects as PathEffects unique_labels = np.unique(c) if legend == "on data": g = sns.scatterplot( x, y, hue=c, palette=cmap, ax=ax, legend=False, **scatter_kwargs ) for i in unique_labels: color_cnt = np.nanmedian(df.iloc[np.where(c == i)[0], :2], 0) txt = ax.text( color_cnt[0], color_cnt[1], str(i), color=font_color, zorder=1000, verticalalignment="center", horizontalalignment="center", weight="bold", ) # c txt.set_path_effects( [ PathEffects.Stroke( linewidth=1.5, foreground=font_color, alpha=0.8 ), # 'w' PathEffects.Normal(), ] ) else: g = sns.scatterplot( x, y, hue=c, palette=cmap, ax=ax, legend="full", **scatter_kwargs ) ax.legend(loc=legend, ncol=unique_labels // 15) return fig, ax
Example #27
Source File: visualize.py From StackedDAE with Apache License 2.0 | 5 votes |
def scatter(x, y, plot_name): """ Used to plot t-SNE projections """ num_colors = len(np.unique(y)) # We choose a color palette with seaborn. palette = np.array(sns.color_palette("hls", num_colors)) # We create a scatter plot. f = plt.figure(figsize=(8, 8)) ax = plt.subplot(aspect='equal') sc = ax.scatter(x[:,0], x[:,1], lw=0, s=40, c=palette[y.astype(np.int)]) plt.xlim(-25, 25) plt.ylim(-25, 25) ax.axis('off') ax.axis('tight') # We add the labels for each digit. txts = [] for i in range(num_colors): # Position of each label. xtext, ytext = np.median(x[y == i, :], axis=0) # if np.isnan(xtext) or np.isnan(ytext): # break txt = ax.text(xtext, ytext, str(i), fontsize=24) txt.set_path_effects([ PathEffects.Stroke(linewidth=5, foreground="w"), PathEffects.Normal()]) txts.append(txt) plt.savefig(plot_name, dpi=120) plt.close()
Example #28
Source File: summary.py From lingvo with Apache License 2.0 | 5 votes |
def CameraImageSummary(frontal_images, run_segment_strings, figsize=(6, 4)): """Write frontal_images as tf.Summaries. Args: frontal_images: Float tensor of frontal camera images: Shape: [batch, height, width, depth]. Expected aspect ratio of 3:2 for visualization. run_segment_strings: Tensor of strings: Shape: [batch, 1]. The associated RunSegment proto for the batch. figsize: Tuple indicating size of camera image. Default is (6, 4) indicating a 3:2 aspect ratio for visualization. """ # Parse the run segment strings to extract the run segment info. run_segment_ids = ExtractRunIds(run_segment_strings) def DrawCameraImage(fig, axes, frontal_image, run_segment_id): """Draw camera image for image summary.""" plot.AddImage( fig=fig, axes=axes, data=frontal_image / 256., show_colorbar=False, suppress_xticks=True, suppress_yticks=True) txt = axes.text( x=0.5, y=0.01, s=run_segment_id, color='blue', fontsize=14, transform=axes.transAxes, horizontalalignment='center') txt.set_path_effects([ path_effects.Stroke(linewidth=3, foreground='lightblue'), path_effects.Normal() ]) with plot.MatplotlibFigureSummary( 'examples', figsize=figsize, max_outputs=10) as fig: # Plot raw frontal image samples for each example. fig.AddSubplot([frontal_images, run_segment_ids], DrawCameraImage)
Example #29
Source File: visualization.py From LipNet with MIT License | 5 votes |
def show_video_subtitle(frames, subtitle): fig, ax = plt.subplots() fig.show() text = plt.text(0.5, 0.1, "", ha='center', va='center', transform=ax.transAxes, fontdict={'fontsize': 15, 'color':'white', 'fontweight': 500}) text.set_path_effects([path_effects.Stroke(linewidth=3, foreground='black'), path_effects.Normal()]) subs = subtitle.split() inc = max(len(frames)/(len(subs)+1), 0.01) i = 0 img = None for frame in frames: sub = " ".join(subs[:int(i/inc)]) text.set_text(sub) if img is None: img = plt.imshow(frame) else: img.set_data(frame) fig.canvas.draw() i += 1
Example #30
Source File: aggregate.py From SAMRI with GNU General Public License v3.0 | 5 votes |
def apply_label(x, color, label, text_side='left', lw=False, x_align=0.0, y_align=0.04, contour_ratio=1.5, text_color=False, ): if text_color: color=text_color ax = plt.gca() if not lw: lw = mpl.rcParams['lines.linewidth'] if text_side == 'left': text = ax.text(x_align, y_align, label, fontweight="bold", color=color, horizontalalignment="left", va="bottom", # For diagnostic purposes, the rasterization workaround should be removed once we can identify why function execution in PythonTeX introduces enlarged bounding boxes. #bbox=dict(facecolor='red', alpha=0.5), transform=ax.transAxes, ) if text_side == 'right': text = ax.text(1.0-x_align, y_align, label, fontweight="bold", color=color, horizontalalignment="right", va="bottom", # For diagnostic purposes, the rasterization workaround should be removed once we can identify why function execution in PythonTeX introduces enlarged bounding boxes. #bbox=dict(facecolor='red', alpha=0.5), rasterized=True, transform=ax.transAxes, ) text.set_path_effects([path_effects.Stroke(linewidth=lw*contour_ratio, foreground='w'), path_effects.Normal()])