本文整理汇总了Python中matplotlib.collections.PatchCollection.set_zorder方法的典型用法代码示例。如果您正苦于以下问题:Python PatchCollection.set_zorder方法的具体用法?Python PatchCollection.set_zorder怎么用?Python PatchCollection.set_zorder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.collections.PatchCollection
的用法示例。
在下文中一共展示了PatchCollection.set_zorder方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plotss
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_zorder [as 别名]
def plotss(data_feats,ax):
"""
Plots secondary structures
:param data_feats: pandas dataframe with position wise features
:param ax: axes object
"""
# plt.figure(figsize=(40, 1),dpi=500)
# ax=plt.subplot(111)
ax.set_axis_off()
xlim=len(data_feats)
#no sec struct
for aai,rowi in data_feats.iterrows():
if not pd.isnull(rowi.loc["Secondary structure"]):
ini=aai+1
break
for aai,rowi in data_feats.iloc[::-1].iterrows():
if not pd.isnull(rowi.loc["Secondary structure"]):
end=aai+1
break
x,y = np.array([[ini, end], [0, 0]])
line = mlines.Line2D(x, y, lw=5,color="black")
line.set_zorder(0)
ax.add_line(line)
patches = []
patches_colors=[]
ssi_ini=""
aai_ini=0
for aai,rowi in data_feats.fillna("").iterrows():
aai=aai-1
ssi=rowi.loc["Secondary structure"]
if ssi!=ssi_ini:
patches,patches_colors,aai_ini,ssi_ini,ax=plotsspatches(ssi,ssi_ini,aai,aai_ini,patches,patches_colors,ax)
collection = PatchCollection(patches, cmap=plt.cm.Accent, alpha=1)
colors = np.linspace(0, 1, len(patches))
collection.set_array(np.array(patches_colors))
collection.set_zorder(20)
ax.add_collection(collection)
# ax.set_xticklabels(range(xlim))
ax.set_xlim((0-0.5,xlim+0.5))
ax.set_ylim((-1.1,1.1))
ax.text(xlim+1,-0.5,"Secondary structure",fontdict={'size': 20})
# plt.show()
return ax
示例2: plotGeometry
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_zorder [as 别名]
def plotGeometry(self, ax = None):
if (ax is None):
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_aspect(1)
self.blockPatch.set_facecolor('#F0F0F0')
self.blockPatch.set_edgecolor('k')
ax.add_patch(self.blockPatch)
pc = PatchCollection(self.channelPatches, match_original = True)
pc.set_facecolor('w')
pc.set_edgecolor('k')
pc.set_zorder(2)
ax.add_collection(pc)
self.plotDimensions(ax)
ax.set_xlim(self.xMin, self.xMax)
ax.set_ylim(self.yMin, self.yMax)
plt.show()
示例3: plotss
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_zorder [as 别名]
def plotss(data_feats,ax,refi_lims,fontsize=20,ticks=False):
"""
Plots secondary structures
:param data_feats: pandas dataframe with position wise features
:param ax: axes object
"""
if not ticks:
ax.set_axis_off()
#no sec struct
for aai,rowi in data_feats.iterrows():
if not pd.isnull(rowi.loc["Secondary structure"]):
ini=aai+1
break
for aai,rowi in data_feats.iloc[::-1].iterrows():
if not pd.isnull(rowi.loc["Secondary structure"]):
end=aai+1
break
x,y = np.array([[ini, end], [0, 0]])
line = mlines.Line2D(x, y, lw=5,color="black")
line.set_zorder(0)
ax.add_line(line)
patches = []
patches_colors=[]
ssi_ini=""
aai_ini=0
for aai,rowi in data_feats.fillna("").iterrows():
aai=aai-1
ssi=rowi.loc["Secondary structure"]
if ssi!=ssi_ini:
patches,patches_colors,aai_ini,ssi_ini,ax=plotsspatches(ssi,ssi_ini,aai,aai_ini,patches,patches_colors,ax)
collection = PatchCollection(patches, cmap=plt.cm.Accent, alpha=1)
colors = np.linspace(0, 1, len(patches))
collection.set_array(np.array(patches_colors))
collection.set_zorder(20)
ax.add_collection(collection)
ax.set_xlim((refi_lims[0]-0.5,refi_lims[1]+0.5))
ax.set_ylim((-1.1,1.1))
ax.text(refi_lims[1]+1,-0.5,"%sSecondary structure" % (r'$\leftarrow$'),fontdict={'size': fontsize})
return ax
示例4: plot
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_zorder [as 别名]
#.........这里部分代码省略.........
"in the second MultiIndex level of bus_sizes"
bus_sizes = bus_sizes.sort_index(level=0, sort_remaining=False)
patches = []
for b_i in bus_sizes.index.levels[0]:
s = bus_sizes.loc[b_i]
radius = s.sum()**0.5
ratios = s/s.sum()
start = 0.25
for i, ratio in ratios.iteritems():
patches.append(Wedge((x.at[b_i], y.at[b_i]), radius,
360*start, 360*(start+ratio),
facecolor=bus_colors[i]))
start += ratio
bus_collection = PatchCollection(patches, match_original=True)
ax.add_collection(bus_collection)
else:
c = pd.Series(bus_colors, index=network.buses.index)
if c.dtype == np.dtype('O'):
c.fillna("b", inplace=True)
c = list(c.values)
s = pd.Series(bus_sizes, index=network.buses.index, dtype="float").fillna(10)
bus_collection = ax.scatter(x, y, c=c, s=s, cmap=bus_cmap)
def as_branch_series(ser):
if isinstance(ser, dict) and set(ser).issubset(branch_components):
return pd.Series(ser)
elif isinstance(ser, pd.Series):
if isinstance(ser.index, pd.MultiIndex):
return ser
index = ser.index
ser = ser.values
else:
index = network.lines.index
return pd.Series(ser,
index=pd.MultiIndex(levels=(["Line"], index),
labels=(np.zeros(len(index)),
np.arange(len(index)))))
line_colors = as_branch_series(line_colors)
line_widths = as_branch_series(line_widths)
if not isinstance(line_cmap, dict):
line_cmap = {'Line': line_cmap}
branch_collections = []
for c in network.iterate_components(branch_components):
l_defaults = defaults_for_branches[c.name]
l_widths = line_widths.get(c.name, l_defaults['width'])
l_nums = None
l_colors = line_colors.get(c.name, l_defaults['color'])
if isinstance(l_colors, pd.Series):
if issubclass(l_colors.dtype.type, np.number):
l_nums = l_colors
l_colors = None
else:
l_colors.fillna(l_defaults['color'], inplace=True)
if not geometry:
segments = (np.asarray(((c.df.bus0.map(x),
c.df.bus0.map(y)),
(c.df.bus1.map(x),
c.df.bus1.map(y))))
.transpose(2, 0, 1))
else:
from shapely.wkt import loads
from shapely.geometry import LineString
linestrings = c.df.geometry.map(loads)
assert all(isinstance(ls, LineString) for ls in linestrings), \
"The WKT-encoded geometry in the 'geometry' column must be composed of LineStrings"
segments = np.asarray(list(linestrings.map(np.asarray)))
if basemap and basemap_present:
segments = np.transpose(bmap(*np.transpose(segments, (2, 0, 1))), (1, 2, 0))
l_collection = LineCollection(segments,
linewidths=l_widths,
antialiaseds=(1,),
colors=l_colors,
transOffset=ax.transData)
if l_nums is not None:
l_collection.set_array(np.asarray(l_nums))
l_collection.set_cmap(line_cmap.get(c.name, None))
l_collection.autoscale()
ax.add_collection(l_collection)
l_collection.set_zorder(1)
branch_collections.append(l_collection)
bus_collection.set_zorder(2)
ax.update_datalim(compute_bbox_with_margins(margin, x, y))
ax.autoscale_view()
ax.set_title(title)
return (bus_collection,) + tuple(branch_collections)
示例5: plot_radial_histogram
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_zorder [as 别名]
def plot_radial_histogram(angles,
counts,
all_angles=None,
include_labels=False,
offset=180.0,
direction=-1,
closed=False,
color=STIM_COLOR):
if all_angles is None:
if len(angles) < 2:
all_angles = np.linspace(0, 315, 8)
else:
all_angles = angles
dth = (all_angles[1] - all_angles[0]) * 0.5
if len(counts) == 0:
max_count = 1
else:
max_count = max(counts)
wedges = []
for count, angle in zip(counts, angles):
angle = angle*direction + offset
wedge = mpatches.Wedge((0,0), count, angle-dth, angle+dth)
wedges.append(wedge)
wedge_coll = PatchCollection(wedges)
wedge_coll.set_facecolor(color)
wedge_coll.set_zorder(2)
angles_rad = (all_angles*direction + offset)*np.pi/180.0
if closed:
border_coll = cplots.radial_circles([max_count])
else:
border_coll = cplots.radial_arcs([max_count],
min(angles_rad),
max(angles_rad))
border_coll.set_facecolor((0,0,0,0))
border_coll.set_zorder(1)
line_coll = cplots.angle_lines(angles_rad, 0, max_count)
line_coll.set_edgecolor((0,0,0,1))
line_coll.set_linestyle(":")
line_coll.set_zorder(1)
ax = plt.gca()
ax.add_collection(wedge_coll)
ax.add_collection(border_coll)
ax.add_collection(line_coll)
if include_labels:
cplots.add_angle_labels(ax, angles_rad, all_angles.astype(int), max_count, (0,0,0,1), offset=max_count*0.1)
ax.set(xlim=(-max_count*1.2, max_count*1.2),
ylim=(-max_count*1.2, max_count*1.2),
aspect=1.0)
else:
ax.set(xlim=(-max_count*1.05, max_count*1.05),
ylim=(-max_count*1.05, max_count*1.05),
aspect=1.0)
示例6: print
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_zorder [as 别名]
#7 substract .1 subtract .05 equals -.15
print(X3)
ax3.set_ylabel('cov ' + betastr)
#fig.set_title(betastr + ' for reg 1st level beta ~ cov score')
ax3.set_xticks(X3)
ax3data = [data_dict[reg][0] for reg in regs1]
ax3dots = [data_dict[reg][1] for reg in regs1]
colors1 = ['purple', 'peachpuff', 'darkred', 'yellow', 'darkblue', 'lightskyblue',
'darkolivegreen', 'lightgreen']
patches = []
for i, dot in enumerate(ax3dots):
circ = mpatches.Ellipse(xy = (X3[i] + .125, ax3dots[i]), width = .05, height = .05, color = 'black')
patches.append(circ)
patches = PatchCollection(patches, match_original=True, zorder=10)
patches.set_zorder(20)
ax3.set_xticks([x + .125 for x in X3])
for i in range(8):
ax3.bar(X3[i], ax3data[i], color=colors1[i], width=0.25, alpha = .8, zorder=2)
ax3.set_xticklabels(labs1)
ax3.set_ylim(min(ax3data) - .25, max(ax3data) + .25)
line_xs = ax3.get_xlim()
line_ys = [0, 0]
ax3.add_line(lines.Line2D(line_xs, line_ys, linewidth=1, alpha=.5, color='black'))
ax3.add_collection(patches)
ax3.set_xlim(X3[0] - .5, X3[-1] + .7)
X2= []
for i, x in enumerate(X3[::2]):
X2.append(np.mean([X3[2*i], X3[2*i + 1]]))
X2 = np.arange(4)
示例7: draw_networkx_edges
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_zorder [as 别名]
#.........这里部分代码省略.........
for c in edge_color]):
# (should check ALL elements)
# list of color letters such as ['k','r','k',...]
edge_colors = tuple([colorConverter.to_rgba(c, alpha)
for c in edge_color])
elif numpy.alltrue([not cb.is_string_like(c)
for c in edge_color]):
# If color specs are given as (rgb) or (rgba) tuples, we're OK
if numpy.alltrue([cb.iterable(c) and len(c) in (3, 4)
for c in edge_color]):
edge_colors = tuple(edge_color)
else:
# numbers (which are going to be mapped with a colormap)
edge_colors = None
else:
raise ValueError('edge_color must consist of either color names or numbers')
else:
if cb.is_string_like(edge_color) or len(edge_color) == 1:
edge_colors = (colorConverter.to_rgba(edge_color, alpha), )
else:
raise ValueError('edge_color must be a single color or list of exactly m colors where m is the number or edges')
edge_collection = None
if not arrows:
edge_collection = LineCollection(edge_pos,
colors=edge_colors,
linewidths=lw,
antialiaseds=(1,),
linestyle=style,
transOffset = ax.transData,
)
edge_collection.set_zorder(1) # edges go behind nodes
edge_collection.set_label(label)
ax.add_collection(edge_collection)
# Note: there was a bug in mpl regarding the handling of alpha values for
# each line in a LineCollection. It was fixed in matplotlib in r7184 and
# r7189 (June 6 2009). We should then not set the alpha value globally,
# since the user can instead provide per-edge alphas now. Only set it
# globally if provided as a scalar.
if cb.is_numlike(alpha):
edge_collection.set_alpha(alpha)
if edge_colors is None:
if edge_cmap is not None:
assert(isinstance(edge_cmap, Colormap))
edge_collection.set_array(numpy.asarray(edge_color))
edge_collection.set_cmap(edge_cmap)
if edge_vmin is not None or edge_vmax is not None:
edge_collection.set_clim(edge_vmin, edge_vmax)
else:
edge_collection.autoscale()
arrow_collection = None
if G.is_directed() and arrows:
# a directed graph hack
# draw thick line segments at head end of edge
# waiting for someone else to implement arrows that will work
arrow_colors = edge_colors
arrow_patches = []
for src, dst in edge_pos:
x1, y1 = src