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)
def text_plotter(x_data, y_data, label_data, color_data, text_positions, axis, txt_widths, txt_height): for x, y, label, color, t, width in zip(x_data, y_data, label_data, color_data, text_positions, txt_widths): text = axis.text(x - width / 2, 0.5 * txt_height + t, f"{label}", rotation=0, color=color) # text.set_size(text.get_size() * 0.75) text.set_path_effects([ path_effects.PathPatchEffect(edgecolor="white", linewidth=0.2, facecolor=color) ]) if 1 == 1: # y != t: axis.vlines( x, y, 0.4 * txt_height + t, linewidth=0.1, colors=color, linestyles="solid", )
def styleBoxplot(bp, fig, ax, n_revisions): def get_ax_size(fig, ax): bbox = ax.get_window_extent().transformed( fig.dpi_scale_trans.inverted()) width, height = bbox.width, bbox.height width *= fig.dpi height *= fig.dpi return width, height for box in bp['boxes']: # change outline color box.set(color='#1b9e77', linewidth=0, path_effects=[ pe.Stroke(linewidth=0.1, foreground='#1b9e77'), pe.Normal() ], facecolor='#1b9e77') box.set_zorder(10) for i, median in enumerate(bp['medians']): median.set(color='#000000', linewidth=2, solid_capstyle="butt", ms=(get_ax_size(fig, ax)[0]) / (n_revisions)) median.set_zorder(11) # median.set_xdata([i + 1 - 0.3, i + 1 + 0.3]) for whisker in bp['whiskers']: whisker.set(color='#CCCCCC', linestyle='-', solid_capstyle="butt") whisker.set_path_effects([ pe.PathPatchEffect(edgecolor='#CCCCCC', linewidth=((get_ax_size(fig, ax)[0]) / (n_revisions)) * 1.08, facecolor='black') ]) for cap in bp['caps']: cap.set(color='#FFFFFF', linewidth=0) # Set only 3 ticks on x ax.set_xticks([1, n_revisions / 2, n_revisions], minor=False) ax.set_xticklabels([1, int(n_revisions / 2), n_revisions], fontdict=None, minor=False) # ax.set_xticklabels(["", "", ""], fontdict=None, minor=False) # Remove extra spines and ticks #ax.spines['top'].set_visible(False) #ax.spines['right'].set_visible(False) ax.spines['left'].set_zorder(100) ax.tick_params(axis='x', which='both', top='off', direction='out') ax.tick_params(axis='y', which='both', right='off', left='on', direction='out')
def update_plot(figure, plot,i): plot.clf() ax = plt.gca() ax.spines['bottom'].set_color(COLOR) ax.spines['top'].set_color(COLOR) ax.spines['right'].set_color(COLOR) ax.spines['left'].set_color(COLOR) ax.set_facecolor(COLOR) ax.get_xaxis().set_visible(False) ax.get_yaxis().set_visible(False) text = fig.text(0.1, 0.1, build_dive_string(FPS, i, DIVE_PROFILE), color='white', ha='left', va='bottom', size=15) text.set_path_effects([path_effects.PathPatchEffect(edgecolor='white', linewidth=1.1, facecolor='white')])
def add_point(self, **kwargs): beta = kwargs.get("beta", None) alpha = kwargs.get("alpha", None) sketch = kwargs.get("sketch", False) # line = kwargs.get('line', True) settings = { "linestyle": "", "marker": kwargs.get("style", "o"), "markersize": kwargs.get("size", 5), "label": kwargs.get("label", ""), "path_effects": [ pe.PathPatchEffect(edgecolor="k", facecolor=kwargs.get("color", "k"), linewidth=0.5) ], "figure": self.figure, } betas, alphas = [], [] pinf, minf = float("inf"), float("-inf") if beta is not None: a_min = kwargs.get("alpha_min", minf) a_max = kwargs.get("alpha_max", pinf) # if a_min == minf and a_max == pinf and line: # plt.axvline(beta, lw=1.5, c='gray', figure=self.figure) self.beta = beta (alpha1, ), (alpha2, ) = self.compute_alpha() self._test_value(alpha1, beta, alphas, betas, a_min, a_max) self._test_value(alpha2, beta, alphas, betas, a_min, a_max) if sketch is True: for alpha in alphas: self.alpha = alpha self.add_sketch(**kwargs) elif alpha is not None: b_min = kwargs.get("beta_min", minf) b_max = kwargs.get("beta_max", pinf) # if b_min == minf and b_max == pinf and line: # plt.axhline(alpha, lw=1, c='gray', figure=self.figure) self.alpha = alpha beta1, beta2 = self.compute_beta_old( ) #TODO potential bug with context self._test_value(beta1, alpha, betas, alphas, b_min, b_max) self._test_value(beta2, alpha, betas, alphas, b_min, b_max) if sketch is True: for beta in betas: self.beta = beta self.add_sketch(**kwargs) plt.plot(betas, alphas, **settings)
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'})
def add_refpoint(self, *args, **kwargs): try: beta = kwargs["beta"] alpha = kwargs["alpha"] except KeyError: raise KeyError("EccwPlot.add_refpoint method awaits at least the " "following key word arguments: 'beta' and 'alpha'") label = kwargs.get("label", "") size = kwargs.get("size", 5) style = kwargs.get("style", "o") color = kwargs.get("color", "k") path_effects = [ pe.PathPatchEffect(edgecolor="k", facecolor=color, linewidth=0.5) ] plt.plot( beta, alpha, ls="", marker=style, ms=size, label=label, path_effects=path_effects, figure=self.figure, )
fig = plt.figure(figsize=(5, 1.5)) text = fig.text(0.5, 0.5, 'Stroke Effect', color='orange', ha='center', va='center', size=36) text.set_path_effects( [path_effects.Stroke(linewidth=5, foreground='b'), path_effects.Normal()]) plt.show() fig = plt.figure(figsize=(5, 1.5)) text = fig.text(0.5, 0.5, 'Hatch Shadow', ha='center', va='center', size=36, weight=1000) text.set_path_effects([ path_effects.PathPatchEffect(offset=(4, -4), hatch='xxxx', facecolor='gray'), path_effects.PathPatchEffect(edgecolor='white', linewidth=1.1, facecolor='green') ]) plt.show()
import matplotlib.pyplot as plt import matplotlib.patheffects as path_effects fig = plt.figure(figsize=(8, 1)) text_val = fig.text(0.02, 0.5, 'Hatch shadow', fontsize=75, weight=1000, va='center') text_val.set_path_effects([path_effects.PathPatchEffect(offset=(4, -4), hatch='xxxx', facecolor='gray'), path_effects.PathPatchEffect(edgecolor='white', linewidth=1.1, facecolor='black')]) plt.show()