本文整理汇总了Python中matplotlib.collections.LineCollection.set_visible方法的典型用法代码示例。如果您正苦于以下问题:Python LineCollection.set_visible方法的具体用法?Python LineCollection.set_visible怎么用?Python LineCollection.set_visible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.collections.LineCollection
的用法示例。
在下文中一共展示了LineCollection.set_visible方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: colorbar_legend
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_visible [as 别名]
def colorbar_legend(ax, values, cmap, vis=True):
"""
Add a vertical colorbar legend to a plot
"""
x_range = ax.get_xlim()[1]-ax.get_xlim()[0]
y_range = ax.get_ylim()[1]-ax.get_ylim()[0]
x = [ax.get_xlim()[0]+x_range*0.05]
y = [ax.get_ylim()[1]-(y_range * 0.25), ax.get_ylim()[1]-(y_range*0.05)]
segs = []
vals=[]
p = (x[0], y[0]+((y[1]-y[0])/256.0))
for i in range(2, 257):
n = (x[0], y[0]+((y[1]-y[0])/256.0)*i)
segs.append((p, n))
p = segs[-1][-1]
vals.append(min(values)+((max(values)-min(values))/256.0)*(i-1))
lcbar = LineCollection(segs, cmap=cmap, lw=15)
lcbar.set_visible(vis)
lcbar.set_array(np.array(vals))
ax.add_collection(lcbar)
lcbar.set_zorder(1)
minlab = str(min(values))[:6]
maxlab = str(max(values))[:6]
ax.text(x[0]+x_range*.02, y[0], minlab, verticalalignment="bottom", visible=vis)
ax.text(x[0]+x_range*.02, y[1], maxlab, verticalalignment="top", visible=vis)
示例2: add_phylorate
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_visible [as 别名]
def add_phylorate(treeplot, rates, nodeidx, vis=True):
"""
Add phylorate plot generated from data analyzed with BAMM
(http://bamm-project.org/introduction.html)
Args:
rates (array): Array of rates along branches
created by r_funcs.phylorate
nodeidx (array): Array of node indices matching rates (also created
by r_funcs.phylorate)
WARNING:
Ladderizing the tree can cause incorrect assignment of Ape node index
numbers. To prevent this, call this function or root.ape_node_idx()
before ladderizing the tree to assign correct Ape node index numbers.
"""
if not treeplot.root.apeidx:
treeplot.root.ape_node_idx()
segments = []
values = []
if treeplot.plottype == "radial":
radpatches = [] # For use in drawing arcs for radial plots
for n in treeplot.root.descendants():
n.rates = rates[nodeidx==n.apeidx]
c = treeplot.n2c[n]
pc = treeplot._path_to_parent(n)[0][1]
xd = c.x - pc[0]
yd = c.y - pc[1]
xseg = xd/len(n.rates)
yseg = yd/len(n.rates)
for i, rate in enumerate(n.rates):
x0 = pc[0] + i*xseg
y0 = pc[1] + i*yseg
x1 = x0 + xseg
y1 = y0 + yseg
segments.append(((x0, y0), (x1, y1)))
values.append(rate)
curverts = treeplot._path_to_parent(n)[0][2:]
curcodes = treeplot._path_to_parent(n)[1][2:]
curcol = RdYlBu(n.rates[0])
radpatches.append(PathPatch(
Path(curverts, curcodes), lw=2, edgecolor = curcol,
fill=False))
else:
for n in treeplot.root.descendants():
n.rates = rates[nodeidx==n.apeidx]
c = treeplot.n2c[n]
pc = treeplot.n2c[n.parent]
seglen = (c.x-pc.x)/len(n.rates)
for i, rate in enumerate(n.rates):
x0 = pc.x + i*seglen
x1 = x0 + seglen
segments.append(((x0, c.y), (x1, c.y)))
values.append(rate)
segments.append(((pc.x, pc.y), (pc.x, c.y)))
values.append(n.rates[0])
lc = LineCollection(segments, cmap=RdYlBu, lw=2)
lc.set_array(np.array(values))
treeplot.add_collection(lc)
lc.set_zorder(1)
if treeplot.plottype == "radial":
arccol = matplotlib.collections.PatchCollection(radpatches,
match_original=True)
treeplot.add_collection(arccol)
arccol.set_visible(vis)
arccol.set_zorder(1)
lc.set_visible(vis)
colorbar_legend(treeplot, values, RdYlBu, vis=vis)
treeplot.figure.canvas.draw_idle()
示例3: HoughDemo
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_visible [as 别名]
#.........这里部分代码省略.........
label=u"直线检测"
),
Group(
Item("dp", label=u"分辨率(像素)"),
Item("mindist", label=u"圆心最小距离(像素)"),
Item("param2", label=u"圆心检查阈值"),
Item("min_radius", label=u"最小半径"),
Item("max_radius", label=u"最大半径"),
label=u"圆检测"
),
Group(
Item("linewidth", label=u"线宽"),
Item("alpha", label=u"alpha"),
HGroup(
Item("check_line", label=u"直线"),
Item("check_circle", label=u"圆"),
),
label=u"绘图参数"
)
)
def __init__(self, **kwargs):
super(HoughDemo, self).__init__(**kwargs)
self.connect_dirty("th2, show_canny, show_blur, rho, theta, hough_th,"
"min_radius, max_radius, blur_sigma,"
"minlen, maxgap, dp, mindist, param2, "
"linewidth, alpha, check_line, check_circle")
self.lines = LineCollection([], linewidths=2, alpha=0.6)
self.axe.add_collection(self.lines)
self.circles = EllipseCollection(
[], [], [],
units="xy",
facecolors="none",
edgecolors="red",
linewidths=2,
alpha=0.6,
transOffset=self.axe.transData)
self.axe.add_collection(self.circles)
def _img_changed(self):
self.img_gray = cv2.cvtColor(self.img, cv2.COLOR_BGR2GRAY)
def draw(self):
img_smooth = cv2.GaussianBlur(self.img_gray, (0, 0), self.blur_sigma, self.blur_sigma)
img_edge = cv2.Canny(img_smooth, self.th2 * 0.5, self.th2)
if self.show_blur and self.show_canny:
show_img = cv2.cvtColor(np.maximum(img_smooth, img_edge), cv2.COLOR_BAYER_BG2BGR)
elif self.show_blur:
show_img = cv2.cvtColor(img_smooth, cv2.COLOR_BAYER_BG2BGR)
elif self.show_canny:
show_img = cv2.cvtColor(img_edge, cv2.COLOR_GRAY2BGR)
else:
show_img = self.img
if self.check_line:
theta = self.theta / 180.0 * np.pi
lines = cv2.HoughLinesP(img_edge,
self.rho, theta, self.hough_th,
minLineLength=self.minlen,
maxLineGap=self.maxgap)
if lines is not None:
lines = lines[0]
lines.shape = -1, 2, 2
self.lines.set_segments(lines)
self.lines.set_visible(True)
else:
self.lines.set_visible(False)
else:
self.lines.set_visible(False)
if self.check_circle:
circles = cv2.HoughCircles(img_smooth, 3,
self.dp, self.mindist,
param1=self.th2,
param2=self.param2,
minRadius=self.min_radius,
maxRadius=self.max_radius)
if circles is not None:
circles = circles[0]
self.circles._heights = self.circles._widths = circles[:, 2]
self.circles.set_offsets(circles[:, :2])
self.circles._angles = np.zeros(len(circles))
self.circles._transOffset = self.axe.transData
self.circles.set_visible(True)
else:
self.circles.set_visible(False)
else:
self.circles.set_visible(False)
self.lines.set_linewidths(self.linewidth)
self.circles.set_linewidths(self.linewidth)
self.lines.set_alpha(self.alpha)
self.circles.set_alpha(self.alpha)
self.draw_image(show_img)