本文整理汇总了Python中matplotlib.collections.PatchCollection.set_linestyle方法的典型用法代码示例。如果您正苦于以下问题:Python PatchCollection.set_linestyle方法的具体用法?Python PatchCollection.set_linestyle怎么用?Python PatchCollection.set_linestyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.collections.PatchCollection
的用法示例。
在下文中一共展示了PatchCollection.set_linestyle方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_linestyle [as 别名]
def draw(options):
files = [f for f in os.listdir(options['outdir']) if f.endswith('.data')]
degrees = list()
diameters = list()
velocities = list()
for f in files:
fin = open(options['outdir']+'/'+f, 'r')
ts = -1
for line in fin:
if line.startswith('#'):
continue
time, degree, diameter, velocity = [t.strip() for t in line.split(',')]
time = int(time)
assert(ts == time-1)
ts = time
try:
degrees[time].append(float(degree))
diameters[time].append(int(diameter))
velocities[time].append(float(velocity))
except IndexError:
degrees.append([float(degree)])
diameters.append([int(diameter)])
velocities.append([float(velocity)])
polies = list()
times = range(len(degrees))
times2 = times + times[::-1]
degrees_conf_upper = [confidence(d)[0] for d in degrees]
degrees_conf_lower = [confidence(d)[1] for d in degrees]
polies.append(conf2poly(times, degrees_conf_upper, degrees_conf_lower, color='blue'))
diameters_conf_upper = [confidence(d)[0] for d in diameters]
diameters_conf_lower = [confidence(d)[1] for d in diameters]
polies.append(conf2poly(times, diameters_conf_upper, diameters_conf_lower, color='blue'))
velocities_conf_upper = [confidence(d)[0] for d in velocities]
velocities_conf_lower = [confidence(d)[1] for d in velocities]
polies.append(conf2poly(times, velocities_conf_upper, velocities_conf_lower, color='green'))
velocities = [scipy.mean(d) for d in velocities]
diameters = [scipy.mean(d) for d in diameters]
degrees = [scipy.mean(d) for d in degrees]
fig = MyFig(options, figsize=(10, 8), xlabel='Time [s]', ylabel='Metric', grid=False, legend=True, aspect='auto', legend_pos='upper right')
patch_collection = PatchCollection(polies, match_original=True)
patch_collection.set_alpha(0.3)
patch_collection.set_linestyle('dashed')
fig.ax.add_collection(patch_collection)
fig.ax.plot(times, degrees, label='Mean degree', color='blue')
fig.ax.plot(times, diameters, label='Diameter', color='red')
fig.ax.plot(times, velocities, label='Mean velocity $[m/s]$', color='green')
fig.ax.set_xlim(0, options['duration'])
y_max = max(max(degrees), max(diameters), max(velocities))
fig.ax.set_ylim(0, y_max+10)
fig.save('metrics', fileformat='pdf')
示例2: data2fig
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_linestyle [as 别名]
def data2fig(data, X, options, legend_title, xlabel, ylabel=r'Reachability~$\reachability$'):
if options['grayscale']:
colors = options['graycm'](pylab.linspace(0, 1, len(data.keys())))
else:
colors = options['color'](pylab.linspace(0, 1, len(data.keys())))
fig = MyFig(options, figsize=(10, 8), xlabel=r'Sources~$\sources$', ylabel=ylabel, grid=False, aspect='auto', legend=True)
for j, nhdp_ht in enumerate(sorted(data.keys())):
d = data[nhdp_ht]
try:
mean_y = [scipy.mean(d[n]) for n in X]
except KeyError:
logging.warning('key \"%s\" not found, continuing...', nhdp_ht)
continue
confs_y = [confidence(d[n])[2] for n in X]
poly = [conf2poly(X, list(numpy.array(mean_y)+numpy.array(confs_y)), list(numpy.array(mean_y)-numpy.array(confs_y)), color=colors[j])]
patch_collection = PatchCollection(poly, match_original=True)
patch_collection.set_alpha(0.3)
patch_collection.set_linestyle('dashed')
fig.ax.add_collection(patch_collection)
fig.ax.plot(X, mean_y, label='$%d$' % nhdp_ht, color=colors[j])
fig.ax.set_xticks(X)
fig.ax.set_xticklabels(['$%s$' % i for i in X])
fig.ax.set_ylim(0,1)
fig.legend_title = legend_title
return fig
示例3: plot_site
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_linestyle [as 别名]
def plot_site(options):
options['prefix'] = 'site'
fig = MyFig(options, figsize=(10, 8), legend=True, grid=False, xlabel=r'Probability $p_s$', ylabel=r'Reachability~$\reachability$', aspect='auto')
fig_vs = MyFig(options, figsize=(10, 8), legend=True, grid=False, xlabel=r'Fraction of Forwarded Packets~$\forwarded$', ylabel=r'Reachability~$\reachability$', aspect='auto')
if options['grayscale']:
colors = options['graycm'](pylab.linspace(0, 1.0, 3))
else:
colors = fu_colormap()(pylab.linspace(0, 1.0, 3))
nodes = 105
axins = None
if options['inset_loc'] >= 0:
axins = zoomed_inset_axes(fig_vs.ax, options['inset_zoom'], loc=options['inset_loc'])
axins.set_xlim(options['inset_xlim'])
axins.set_ylim(options['inset_ylim'])
axins.set_xticklabels([])
axins.set_yticklabels([])
mark_inset(fig_vs.ax, axins, loc1=2, loc2=3, fc="none", ec="0.5")
for i, (name, label) in enumerate(names):
data = parse_site_only(options['datapath'][0], name)
rs = numpy.array([r for p, r, std, conf, n, fw, fw_std, fw_conf in data if r <= options['limit']])
fws = numpy.array([fw for p, r, std, conf, n, fw, fw_std, fw_conf in data if r <= options['limit']])/(nodes-1)
ps = numpy.array([p for p, r, std, conf, n, fw, fw_std, fw_conf in data]) #[0:len(rs)])
yerr = numpy.array([conf for p,r,std,conf, n, fw, fw_std, fw_conf in data]) #[0:len(rs)])
patch_collection = PatchCollection([conf2poly(ps, list(rs+yerr), list(rs-yerr), color=colors[i])], match_original=True)
patch_collection.set_alpha(0.3)
patch_collection.set_linestyle('dashed')
fig.ax.add_collection(patch_collection)
fig.ax.plot(ps, rs, label=label, color=colors[i])
fig_vs.ax.plot(fws, rs, label=label, color=colors[i])
if axins:
axins.plot(fws, rs, color=colors[i])
fig.ax.set_ylim(0, options['limit'])
fig.legend_title = 'Graph'
fig.save('graphs')
fig_vs.legend_title = 'Graph'
fig_vs.ax.set_xlim(0,1)
fig_vs.ax.set_ylim(0,1)
fig_vs.save('vs_pb')
示例4: plot_bond_site
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_linestyle [as 别名]
#.........这里部分代码省略.........
if options['grayscale']:
pcolor = fig_pcolor.ax.pcolormesh(X, Y, Z, vmin=0, vmax=1, cmap=options['graycm'])
else:
pcolor = fig_pcolor.ax.pcolormesh(X, Y, Z, vmin=0, vmax=1, cmap=fu_colormap())
cbar = fig_pcolor.colorbar(pcolor)
cbar.set_ticks(pylab.linspace(0, 1, 11))
data = calc_metrics(merge)
tuples = [(ps, pb, r) for ps, pb, r, _std, _conf, _n, _fw_mean, _fw_std, _fw_std in data]
contour_plot(tuples)
nodes = options['nodes']
for i, bin in enumerate(pylab.linspace(0, 1, bins)):
r_pb1 = numpy.array([r for _ps, pb, r, _std, _conf, _n, _fw_mean, _fw_std, _fw_conf in data if abs(pb - bin) < epsilon*2])
fw_pb1 = numpy.array([fw_mean for _ps, pb, _r, _std, _conf, _n, fw_mean, _fw_std, _fw_conf in data if abs(pb - bin) < epsilon*2])/nodes
fw_conf_pb1 = numpy.array([fw_conf for _ps, pb, _r, _std, _conf, _n, fw_mean, _fw_std, fw_conf in data if abs(pb - bin) < epsilon*2])/nodes
conf_pb1 = numpy.array([conf for _ps, pb, _r, _std, conf, _n, _fw_mean, _fw_std, _fw_conf in data if abs(pb - bin) < epsilon*2])
p_pb1 = numpy.array([ps for ps, pb, _r, _std, _conf, _n, _fw_mean, _fw_std, _fw_conf in data if abs(pb - bin) < epsilon*2])
r_ps1 = numpy.array([r for ps, _pb, r, _std, _conf, n, _fw_mean, _fw_std, _fw_conf in data if abs(ps - bin) < epsilon*2])
fw_ps1 = numpy.array([fw_mean for ps, _pb, r, _std, _conf, n, fw_mean, _fw_std, _fw_conf in data if abs(ps - bin) < epsilon*2])/nodes
fw_conf_ps1 = numpy.array([fw_conf for ps, _pb, r, _std, _conf, n, fw_mean, _fw_std, fw_conf in data if abs(ps - bin) < epsilon*2])/nodes
conf_ps1 = numpy.array([conf for ps, _pb, _r, _std, conf, _n, _fw_mean, _fw_std, _fw_conf in data if abs(ps - bin) < epsilon*2])
p_ps1 = numpy.array([pb for ps, pb, _r, _std, _conf, n, _fw_mean, _fw_std, _fw_conf in data if abs(ps - bin) < epsilon*2])
assert(len(r_pb1) == len(conf_pb1) == len(p_pb1))
assert(len(r_ps1) == len(conf_ps1) == len(p_ps1))
if len(r_pb1) > 0:
if not options['noconfidence']:
patch_collection = PatchCollection([conf2poly(p_pb1, list(r_pb1+conf_pb1), list(r_pb1-conf_pb1), color=colors[i])], match_original=True)
patch_collection.set_alpha(0.3)
patch_collection.set_linestyle('dashed')
fig_site.ax.add_collection(patch_collection)
fig_site.ax.plot(p_pb1, r_pb1, color=colors[i], label='$%.2f$' % bin)
if fig_vs_pb:
fig_vs_pb.ax.plot(fw_pb1, r_pb1, color=colors[i], label='$%.2f$' % bin)
patch_collection = PatchCollection([conf2poly(p_pb1, list(fw_pb1+fw_conf_pb1), list(fw_pb1-fw_conf_pb1), color=colors[i])], match_original=True)
patch_collection.set_alpha(0.3)
patch_collection.set_linestyle('dashed')
fig_fw_pb.ax.add_collection(patch_collection)
fig_fw_pb.ax.plot(p_pb1, fw_pb1, color=colors[i], label='$%.2f$' % bin)
else:
fig_site.ax.plot(p_pb1, r_pb1, color=colors[i], label='$%.2f$' % bin)
if fig_vs_pb:
fig_vs_pb.ax.plot(fw_pb1, r_pb1, color=colors[i], label='$%.2f$' % bin)
fig_fw_pb.ax.plot(p_pb1, fw_pb1, color=colors[i], label='$%.2f$' % bin)
if len(r_ps1) > 0:
if not options['noconfidence']:
patch_collection = PatchCollection([conf2poly(p_ps1, list(r_ps1+conf_ps1), list(r_ps1-conf_ps1), color=colors[i])], match_original=True)
patch_collection.set_alpha(0.3)
patch_collection.set_linestyle('dashed')
fig_bond.ax.add_collection(patch_collection)
fig_bond.ax.plot(p_ps1, r_ps1, color=colors[i], label='$%.2f$' % bin)
if fig_vs_ps:
fig_vs_ps.ax.plot(fw_ps1, r_ps1, color=colors[i], label='$%.2f$' % bin)
patch_collection = PatchCollection([conf2poly(p_ps1, list(fw_ps1+fw_conf_ps1), list(fw_ps1-fw_conf_ps1), color=colors[i])], match_original=True)
patch_collection.set_alpha(0.3)
patch_collection.set_linestyle('dashed')
fig_fw_ps.ax.add_collection(patch_collection)
fig_fw_ps.ax.plot(p_ps1, fw_ps1, color=colors[i], label='$%.2f$' % bin)
示例5: Plot2D
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_linestyle [as 别名]
def Plot2D(self, xy=None, elecon=None, u=None, color=None, ax=None, show=0,
weight=None, colorby=None, linestyle='-', label=None, xlim=None,
ylim=None, filename=None, **kwds):
assert self.dimensions == 2
from matplotlib.patches import Polygon
import matplotlib.lines as mlines
from matplotlib.collections import PatchCollection
from matplotlib.cm import coolwarm, Spectral
import matplotlib.pyplot as plt
if xy is None:
xy = array(self.coord)
if elecon is None:
elecon = []
for blk in self.eleblx:
elecon.extend(blk.elecon.tolist())
elecon = asarray(elecon)
if u is not None:
xy += u.reshape(xy.shape)
patches = []
for points in xy[elecon[:]]:
quad = Polygon(points, True)
patches.append(quad)
if ax is None:
fig, ax = plt.subplots()
#colors = 100 * random.rand(len(patches))
p = PatchCollection(patches, linewidth=weight, **kwds)
if colorby is not None:
colorby = asarray(colorby).flatten()
if len(colorby) == len(xy):
# average value in element
colorby = array([average(colorby[points]) for points in elecon])
p.set_cmap(Spectral) #coolwarm)
p.set_array(colorby)
p.set_clim(vmin=colorby.min(), vmax=colorby.max())
fig.colorbar(p)
else:
p.set_edgecolor(color)
p.set_facecolor('None')
p.set_linewidth(weight)
p.set_linestyle(linestyle)
if label:
ax.plot([], [], color=color, linestyle=linestyle, label=label)
ax.add_collection(p)
if not ylim:
ymin, ymax = amin(xy[:,1]), amax(xy[:,1])
dy = max(abs(ymin*.05), abs(ymax*.05))
ax.set_ylim([ymin-dy, ymax+dy])
else:
ax.set_ylim(ylim)
if not xlim:
xmin, xmax = amin(xy[:,0]), amax(xy[:,0])
dx = max(abs(xmin*.05), abs(xmax*.05))
ax.set_xlim([xmin-dx, xmax+dx])
else:
ax.set_xlim(xlim)
ax.set_aspect('equal')
if show:
plt.show()
if filename is not None:
plt.legend()
plt.savefig(filename, transparent=True,
bbox_inches="tight", pad_inches=0)
return ax