本文整理汇总了Python中matplotlib.patheffects.withStroke函数的典型用法代码示例。如果您正苦于以下问题:Python withStroke函数的具体用法?Python withStroke怎么用?Python withStroke使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了withStroke函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createAARText
def createAARText(self):
"""Creates the text for airspeed, altitude and climb rate."""
self.airspeedText = self.axes.text(
self.rightPos - (self.vertSize / 10.0),
-0.97 + (2 * self.vertSize) - (self.vertSize / 10.0),
"AS: %.1f m/s" % self.airspeed,
color="w",
size=self.fontSize,
ha="right",
)
self.altitudeText = self.axes.text(
self.rightPos - (self.vertSize / 10.0),
-0.97 + self.vertSize - (0.5 * self.vertSize / 10.0),
"ALT: %.1f m " % self.relAlt,
color="w",
size=self.fontSize,
ha="right",
)
self.climbRateText = self.axes.text(
self.rightPos - (self.vertSize / 10.0),
-0.97,
"CR: %.1f m/s" % self.climbRate,
color="w",
size=self.fontSize,
ha="right",
)
self.airspeedText.set_path_effects([PathEffects.withStroke(linewidth=1, foreground="k")])
self.altitudeText.set_path_effects([PathEffects.withStroke(linewidth=1, foreground="k")])
self.climbRateText.set_path_effects([PathEffects.withStroke(linewidth=1, foreground="k")])
示例2: make_node_label
def make_node_label(ax, num, x, max_order):
tla = x["node %d TLA"%(num)]
# add a rectangle
attr = node_attributes[tla]
fill_color(ax, 'white')
fill_color(ax, attr['color'], alpha=0.6)
# add the text
txt_core = tla
txt = plt.text(0.35,0.5, txt_core, fontsize=fontsize_big, horizontalalignment='center',
verticalalignment='center' ) #, backgroundcolor='white', color='black')
plt.setp(txt, path_effects=[PathEffects.withStroke(linewidth=3, foreground="w")])
node_order = x["node %d order"%(num)]
# if this was an in node, make it an out node
if x["node %d inout"%(num)] == 'IN':
node_order = max_order[tla] - node_order + 1
txt = plt.text(0.83,0.75, "%d"%node_order, fontsize=fontsize_small, horizontalalignment='center',
verticalalignment='center' ) #, backgroundcolor='white', color='black')
plt.setp(txt, path_effects=[PathEffects.withStroke(linewidth=3, foreground="w")])
txt = plt.text(0.83,0.38, "-", fontsize=fontsize_small*2, horizontalalignment='center',
verticalalignment='center' ) #, backgroundcolor='white', color='black')
plt.setp(txt, path_effects=[PathEffects.withStroke(linewidth=3, foreground="w")])
txt = plt.text(0.83,0.25, "%d"%max_order[tla], fontsize=fontsize_small, horizontalalignment='center',
verticalalignment='center' ) #, backgroundcolor='white', color='black')
plt.setp(txt, path_effects=[PathEffects.withStroke(linewidth=3, foreground="w")])
plt.axis('off')
return attr['color']
示例3: spear_marginal_four
def spear_marginal_four(stages):
"""
Plot histograms of the spearman rank for sampled draws from the DPDFs.
"""
# Plot settings
ax_labels = [r'$\rho_{\rm spear}$',
r'$f$']
stages_labels = [r'${\rm Starless}$',
r'${\rm H_2O \ \ N}$',
r'${\rm IR \ \ Y}$',
r'${\rm H_2O \ \ Y}$']
colors = ['green', 'SlateBlue', 'red', 'DodgerBlue']
hist_kwargs = {'histtype': 'stepfilled', 'edgecolor': 'black', 'bins':
_np.linspace(0, 1, 100)}
xcol = 'avg_diam'
ycol = 'hco_fwhm'
# Calculate ranks
good_kdars = ['T', 'F', 'N']
stages = [df[(df[xcol].notnull()) & (df[ycol].notnull()) &
((df['neighbor_KDAR'].isin(good_kdars)) |
(df['dpdf_KDAR'].isin(good_kdars)))] for df in stages]
spears = [[], [], [], []]
for i, stage in enumerate(stages):
print i
widths = stage[ycol].values
# Draw distances
radii_samples = dpdf_calc.gen_stage_area_samples(stage, nsample=1e4,
radius=True, flatten=False) / 1e6
# Calculate spearman rank for each draw
for radii in radii_samples.T:
spearman_rank = spearmanr(widths, radii)[0]
spears[i].append(spearman_rank)
# Begin plot
fig, axes = _plt.subplots(figsize=(12, 1.5), nrows=1, ncols=4, sharex=True,
sharey=True)
for i, ax in enumerate(axes.flatten()):
ax.hist(spears[i], facecolor=colors[i], **hist_kwargs)
med_spear = _np.median(spears[i])
ax.plot(med_spear, 40, 'Dk', markersize=5)
spear_label = r'$\langle\rho_{\rm spear}\rangle_{1/2} = ' \
+ str(med_spear)[:4] + r'$'
# Plot attributes
if i == 0:
ax.set_ylabel(ax_labels[1])
ax.set_xlabel(ax_labels[0])
ax.set_xticks([0.2, 0.4, 0.6, 0.8])
ax.set_yticklabels([])
stage_txt = ax.annotate(stages_labels[i], xy=(0.70, 0.75), xycoords='axes fraction',
fontsize=10)
spear_txt = ax.annotate(spear_label, xy=(0.55, 0.625), xycoords='axes fraction',
fontsize=10)
stage_txt.set_path_effects([PathEffects.withStroke(linewidth=2,
foreground='w')])
spear_txt.set_path_effects([PathEffects.withStroke(linewidth=2,
foreground='w')])
_plt.subplots_adjust(top=0.9, bottom=0.25, left=0.1, right=0.9, hspace=0.05,
wspace=0.05)
_plt.savefig('size_linewidth_spearman_{0}_{1}.pdf'.format('hco', '4panel'))
return fig, axes
示例4: plot_all_params
def plot_all_params(filen='obj_props', out_filen='ppv_grid', log_Z=False):
"""
Read in the pickled tree parameter dictionary and plot the containing
parameters.
Parameters
----------
filen : str
File name of pickled reduced property dictionary.
out_filen : str
Basename of plots, the key of the object dictionary is appended to the
filename.
log_Z : bool
Create plots with logarithmic Z axis
"""
cmap = cm.RdYlBu_r
obj_dict = pickle.load(open(filen + '.pickle', 'rb'))
X = obj_dict['velo']
Y = obj_dict['angle']
X = ndimage.zoom(X, 3)
Y = ndimage.zoom(Y, 3)
W = ndimage.zoom(obj_dict['conflict_frac'], 3)
obj_dict['reward'] = np.log10(obj_dict['new_kdar_assoc']) / obj_dict['conflict_frac']
params = [(k, v) for k, v in obj_dict.iteritems()
if k not in ['velo', 'angle']]
clevels = [0.06, 0.12, 0.20, 0.30, 0.5]
for key, Z in params:
print ':: ', key
fig, ax = plt.subplots(figsize=(4, 4.5))
cax = fig.add_axes([0.15, 0.88, 0.8, 0.03])
plt.subplots_adjust(top=0.85, left=0.15, right=0.95, bottom=0.125)
if log_Z:
Z = np.log10(Z)
key += '_(log)'
Z = ndimage.zoom(Z, 3)
pc = ax.pcolor(X, Y, Z, cmap=cmap, vmin=Z.min(), vmax=Z.max())
cb = plt.colorbar(pc, ax=ax, cax=cax, orientation='horizontal',
ticklocation='top')
ax.plot([4], [0.065], 'ko', ms=10, markerfacecolor='none', markeredgewidth=2)
# Contours for conflict frac
cn = ax.contour(X, Y, W, levels=clevels,
colors='k', linewidth=2)
plt.setp(cn.collections,
path_effects=[PathEffects.withStroke(linewidth=2,
foreground='w')])
cl = ax.clabel(cn, fmt='%1.2f', inline=1, fontsize=10,
use_clabeltext=True)
plt.setp(cl, path_effects=[PathEffects.withStroke(linewidth=2,
foreground='w')])
# Labels
ax.set_xlabel(r'$v \ \ [{\rm km \ s^{-1}}]$')
ax.set_ylabel(r'$\theta \ \ [^{\circ}]$')
# Limits
ax.set_xlim([X.min(), X.max()])
ax.set_ylim([Y.min(), Y.max()])
# Save
plt.savefig(out_filen + '_' + key + '.pdf')
plt.savefig(out_filen + '_' + key + '.png', dpi=300)
plt.close()
示例5: createAARText
def createAARText(self):
'''Creates the text for airspeed, altitude and climb rate.'''
self.airspeedText = self.axes.text(self.rightPos-(self.vertSize/10.0),-0.97+(2*self.vertSize)-(self.vertSize/10.0),'AS: %.1f m/s' % self.airspeed,color='w',size=self.fontSize,ha='right')
self.altitudeText = self.axes.text(self.rightPos-(self.vertSize/10.0),-0.97+self.vertSize-(0.5*self.vertSize/10.0),'ALT: %.1f m ' % self.relAlt,color='w',size=self.fontSize,ha='right')
self.climbRateText = self.axes.text(self.rightPos-(self.vertSize/10.0),-0.97,'CR: %.1f m/s' % self.climbRate,color='w',size=self.fontSize,ha='right')
self.airspeedText.set_path_effects([PathEffects.withStroke(linewidth=1,foreground='k')])
self.altitudeText.set_path_effects([PathEffects.withStroke(linewidth=1,foreground='k')])
self.climbRateText.set_path_effects([PathEffects.withStroke(linewidth=1,foreground='k')])
示例6: createRPYText
def createRPYText(self):
'''Creates the text for roll, pitch and yaw.'''
self.rollText = self.axes.text(self.leftPos+(self.vertSize/10.0),-0.97+(2*self.vertSize)-(self.vertSize/10.0),'Roll: %.2f' % self.roll,color='w',size=self.fontSize)
self.pitchText = self.axes.text(self.leftPos+(self.vertSize/10.0),-0.97+self.vertSize-(0.5*self.vertSize/10.0),'Pitch: %.2f' % self.pitch,color='w',size=self.fontSize)
self.yawText = self.axes.text(self.leftPos+(self.vertSize/10.0),-0.97,'Yaw: %.2f' % self.yaw,color='w',size=self.fontSize)
self.rollText.set_path_effects([PathEffects.withStroke(linewidth=1,foreground='k')])
self.pitchText.set_path_effects([PathEffects.withStroke(linewidth=1,foreground='k')])
self.yawText.set_path_effects([PathEffects.withStroke(linewidth=1,foreground='k')])
示例7: spear_size_linewidth_four
def spear_size_linewidth_four(stages):
"""
"""
# TODO add doc
ax_labels = [r'$R \ \ [{\rm pc}]$',
r'$\Delta v_{\rm HCO^+} \ \ [{\rm km \ s^{-1}}]$']
stages_labels = [r'${\rm Starless}$',
r'${\rm H_2O \ \ N}$',
r'${\rm IR \ \ Y}$',
r'${\rm H_2O \ \ Y}$']
colors = ['green', 'SlateBlue', 'red', 'DodgerBlue']
xcol = 'avg_diam'
ycol = 'hco_fwhm'
# Plot limits
stages = [df[(df[xcol].notnull()) & (df[ycol].notnull())] for df in stages]
xmin = _np.nanmin([df[xcol].min() for df in stages])
xmax = _np.nanmax([df[xcol].max() for df in stages])
ymin = _np.nanmin([df[ycol].min() for df in stages])
ymax = _np.nanmax([df[ycol].max() for df in stages])
spears = [spearmanr(df[xcol].values, df[ycol].values) for df in stages]
spears = [str(i[0])[:4] for i in spears]
spears = [r'$\rho_{\rm spear} = ' + s + r'$' for s in spears]
# Plot settings
error_kwargs = {'elinewidth': 0.5, 'ecolor': 'black', 'capsize': 0, 'fmt':
'D', 'ms': 2.5}
# Begin plot
fig, axes = _plt.subplots(figsize=(12, 4), nrows=1, ncols=4, sharex=True,
sharey=True)
for i, ax in enumerate(axes.flatten()):
# Error bar plot
x = stages[i][xcol].values
y = stages[i][ycol].values
xerr = stages[i][xcol].values * 0.1
yerr = stages[i][ycol + '_err'].values
ax.errorbar(x, y, xerr=xerr, yerr=yerr, color=colors[i], **error_kwargs)
linex = _np.linspace(0.01, 30, 100)
liney = linex**(0.50) * 2.0
ax.plot(linex, liney, 'k--', alpha=0.5)
# Plot attributes
ax.set_xlim([10**(_np.log10(xmin) - 0.2), 10**(_np.log10(xmax) + 0.2)])
ax.set_ylim([10**(_np.log10(ymin) - 0.2), 10**(_np.log10(ymax) + 0.2)])
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel(ax_labels[0])
if i == 0:
ax.set_ylabel(ax_labels[1])
stage_txt = ax.annotate(stages_labels[i], xy=(0.70, 0.90), xycoords='axes fraction',
fontsize=10)
spear_txt = ax.annotate(spears[i], xy=(0.65, 0.85), xycoords='axes fraction',
fontsize=10)
stage_txt.set_path_effects([PathEffects.withStroke(linewidth=2,
foreground='w')])
spear_txt.set_path_effects([PathEffects.withStroke(linewidth=2,
foreground='w')])
_plt.subplots_adjust(top=0.9, bottom=0.15, left=0.1, right=0.9, hspace=0.05,
wspace=0.05)
_plt.savefig('size_linewidth_{0}_{1}.pdf'.format('hco', '4panel'))
return fig, axes
示例8: test_patheffect2
def test_patheffect2():
ax2 = plt.subplot(111)
arr = np.arange(25).reshape((5, 5))
ax2.imshow(arr)
cntr = ax2.contour(arr, colors="k")
plt.setp(cntr.collections, path_effects=[withStroke(linewidth=3, foreground="w")])
clbls = ax2.clabel(cntr, fmt="%2.0f", use_clabeltext=True)
plt.setp(clbls, path_effects=[withStroke(linewidth=3, foreground="w")])
示例9: createBatteryBar
def createBatteryBar(self):
'''Creates the bar to display current battery percentage.'''
self.batOutRec = patches.Rectangle((self.rightPos-(1.3+self.rOffset)*self.batWidth,1.0-(0.1+1.0+(2*0.075))*self.batHeight),self.batWidth*1.3,self.batHeight*1.15,facecolor='darkgrey',edgecolor='none')
self.batInRec = patches.Rectangle((self.rightPos-(self.rOffset+1+0.15)*self.batWidth,1.0-(0.1+1+0.075)*self.batHeight),self.batWidth,self.batHeight,facecolor='lawngreen',edgecolor='none')
self.batPerText = self.axes.text(self.rightPos - (self.rOffset+0.65)*self.batWidth,1-(0.1+1+(0.075+0.15))*self.batHeight,'%.f' % self.batRemain,color='w',size=self.fontSize,ha='center',va='top')
self.batPerText.set_path_effects([PathEffects.withStroke(linewidth=1,foreground='k')])
self.voltsText = self.axes.text(self.rightPos-(self.rOffset+1.3+0.2)*self.batWidth,1-(0.1+0.05+0.075)*self.batHeight,'%.1f V' % self.voltage,color='w',size=self.fontSize,ha='right',va='top')
self.ampsText = self.axes.text(self.rightPos-(self.rOffset+1.3+0.2)*self.batWidth,1-self.vertSize-(0.1+0.05+0.1+0.075)*self.batHeight,'%.1f A' % self.current,color='w',size=self.fontSize,ha='right',va='top')
self.voltsText.set_path_effects([PathEffects.withStroke(linewidth=1,foreground='k')])
self.ampsText.set_path_effects([PathEffects.withStroke(linewidth=1,foreground='k')])
self.axes.add_patch(self.batOutRec)
self.axes.add_patch(self.batInRec)
示例10: setup
def setup(dpi=300, sketch=(1, 100, 2), theme='light'):
"""Setup travelmaps."""
# Customized plt.xkcd()-settings
# http://jakevdp.github.io/blog/2013/07/10/XKCD-plots-in-matplotlib
rcParams['font.family'] = ['Humor Sans', 'Comic Sans MS']
rcParams['font.size'] = 8.0
rcParams['path.sketch'] = sketch
rcParams['axes.linewidth'] = 1.0
rcParams['lines.linewidth'] = 1.0
rcParams['grid.linewidth'] = 0.0
rcParams['axes.unicode_minus'] = False
if theme=='dark':
rcParams['path.effects'] = [patheffects.withStroke(linewidth=2, foreground="k")]
rcParams['figure.facecolor'] = 'black'
rcParams['figure.edgecolor'] = 'black'
rcParams['lines.color'] = 'white'
rcParams['patch.edgecolor'] = 'white'
rcParams['text.color'] = 'white'
rcParams['axes.facecolor'] = 'black'
rcParams['axes.edgecolor'] = 'white'
rcParams['axes.labelcolor'] = 'white'
rcParams['xtick.color'] = 'white'
rcParams['ytick.color'] = 'white'
rcParams['grid.color'] = 'white'
rcParams['savefig.facecolor'] = 'black'
rcParams['savefig.edgecolor'] = 'black'
else:
rcParams['path.effects'] = [patheffects.withStroke(linewidth=2, foreground="w")]
rcParams['figure.facecolor'] = 'white'
rcParams['figure.edgecolor'] = 'white'
rcParams['lines.color'] = 'black'
rcParams['patch.edgecolor'] = 'black'
rcParams['text.color'] = 'black'
rcParams['axes.facecolor'] = 'white'
rcParams['axes.edgecolor'] = 'black'
rcParams['axes.labelcolor'] = 'black'
rcParams['xtick.color'] = 'black'
rcParams['ytick.color'] = 'black'
rcParams['grid.color'] = 'black'
rcParams['savefig.facecolor'] = 'white'
rcParams['savefig.edgecolor'] = 'white'
# *Bayesian Methods for Hackers*-colour-cylce
# (https://github.com/pkgpl/PythonProcessing/blob/master/results/matplotlibrc.bmh.txt)
rcParams['axes.prop_cycle'] = plt.cycler('color', ['#348ABD', '#A60628', '#7A68A6', '#467821', '#D55E00',
'#CC79A7', '#56B4E9', '#009E73', '#F0E442', '#0072B2'])
# Adjust dpi, so figure on screen and savefig looks the same
rcParams['figure.dpi'] = dpi
rcParams['savefig.dpi'] = dpi
示例11: createBatteryBar
def createBatteryBar(self):
"""Creates the bar to display current battery percentage."""
self.batOutRec = patches.Rectangle(
(self.rightPos - (1.3 + self.rOffset) * self.batWidth, 1.0 - (0.1 + 1.0 + (2 * 0.075)) * self.batHeight),
self.batWidth * 1.3,
self.batHeight * 1.15,
facecolor="darkgrey",
edgecolor="none",
)
self.batInRec = patches.Rectangle(
(self.rightPos - (self.rOffset + 1 + 0.15) * self.batWidth, 1.0 - (0.1 + 1 + 0.075) * self.batHeight),
self.batWidth,
self.batHeight,
facecolor="lawngreen",
edgecolor="none",
)
self.batPerText = self.axes.text(
self.rightPos - (self.rOffset + 0.65) * self.batWidth,
1 - (0.1 + 1 + (0.075 + 0.15)) * self.batHeight,
"%.f" % self.batRemain,
color="w",
size=self.fontSize,
ha="center",
va="top",
)
self.batPerText.set_path_effects([PathEffects.withStroke(linewidth=1, foreground="k")])
self.voltsText = self.axes.text(
self.rightPos - (self.rOffset + 1.3 + 0.2) * self.batWidth,
1 - (0.1 + 0.05 + 0.075) * self.batHeight,
"%.1f V" % self.voltage,
color="w",
size=self.fontSize,
ha="right",
va="top",
)
self.ampsText = self.axes.text(
self.rightPos - (self.rOffset + 1.3 + 0.2) * self.batWidth,
1 - self.vertSize - (0.1 + 0.05 + 0.1 + 0.075) * self.batHeight,
"%.1f A" % self.current,
color="w",
size=self.fontSize,
ha="right",
va="top",
)
self.voltsText.set_path_effects([PathEffects.withStroke(linewidth=1, foreground="k")])
self.ampsText.set_path_effects([PathEffects.withStroke(linewidth=1, foreground="k")])
self.axes.add_patch(self.batOutRec)
self.axes.add_patch(self.batInRec)
示例12: test_patheffect1
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)
示例13: __annotate_plot
def __annotate_plot(self, x, y):
self.__clear_markers()
if x is None or y is None:
return
start, stop = self.axes.get_xlim()
textX = ((stop - start) / 50.0) + x
text = '{}\n{}'.format(*format_precision(self.settings, x, y,
fancyUnits=True))
if matplotlib.__version__ < '1.3':
self.axes.annotate(text,
xy=(x, y), xytext=(textX, y),
ha='left', va='top', size='x-small',
gid='peak')
self.axes.plot(x, y, marker='x', markersize=10, color='w',
mew=3, gid='peak')
self.axes.plot(x, y, marker='x', markersize=10, color='r',
gid='peak')
else:
effect = patheffects.withStroke(linewidth=2, foreground="w",
alpha=0.75)
self.axes.annotate(text,
xy=(x, y), xytext=(textX, y),
ha='left', va='top', size='x-small',
path_effects=[effect], gid='peak')
self.axes.plot(x, y, marker='x', markersize=10, color='r',
path_effects=[effect], gid='peak')
示例14: plot_wrapper
def plot_wrapper(model, resolution, ax, nonzero_frequency_mask):
xy = []
r = []
w = []
f = []
for year in range(2003, 2011):
_, test, coefficients, circle_parameters = read_results(model, year, resolution)
latlons, radiuses, features = zip(*circle_parameters)
radiuses = np.array(radiuses) / 10.
xy.extend(latlons)
r.extend(radiuses.tolist())
w.extend(coefficients)
f.extend(features)
w = np.power(w, 2)
heatmap = earth_to_square(xy, r, w, f, nonzero_frequency_mask)
# ax = plt.subplot(1, 1, 1, aspect='equal')
# plot_single_circle_grid(centers, radiuses, ax, intensities, grid=False, alpha=0.2)
image = ax.pcolormesh(heatmap, cmap='jet')
# plt.title("Wrapped Ridge (WR)", fontsize=14)
plt.ylim((0, 112))
plt.xlim((0, 112))
plt.xticks([])
plt.yticks([])
ax.annotate(int(resolution), xy=(4, 98), fontsize=30,
path_effects=[PathEffects.withStroke(linewidth=3, foreground="w")])
# plt.savefig("/Users/mecl/gp_mecl/exp/swe/heatmap_ridge.pdf")
# plt.show()
return image
示例15: __annotate_plot
def __annotate_plot(self):
f, l, t = self.extent.get_peak_flt()
when = format_time(t)
tPos = utc_to_mpl(t)
text = '{}\n{}\n{when}'.format(*format_precision(self.settings, f, l,
fancyUnits=True),
when=when)
if matplotlib.__version__ < '1.3':
self.axes.text(f, tPos, l,
text,
ha='left', va='bottom', size='x-small', gid='peak')
self.axes.plot([f], [tPos], [l], marker='x', markersize=10,
mew=3, color='w', gid='peak')
self.axes.plot([f], [tPos], [l], marker='x', markersize=10,
color='r', gid='peak')
else:
effect = patheffects.withStroke(linewidth=2, foreground="w",
alpha=0.75)
self.axes.text(f, tPos, l,
text,
ha='left', va='bottom', size='x-small', gid='peak',
path_effects=[effect])
self.axes.plot([f], [tPos], [l], marker='x', markersize=10,
color='r', gid='peak', path_effects=[effect])