本文整理汇总了Python中mpl_toolkits.mplot3d.art3d.Line3DCollection方法的典型用法代码示例。如果您正苦于以下问题:Python art3d.Line3DCollection方法的具体用法?Python art3d.Line3DCollection怎么用?Python art3d.Line3DCollection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpl_toolkits.mplot3d.art3d
的用法示例。
在下文中一共展示了art3d.Line3DCollection方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: colored_line_collection
# 需要导入模块: from mpl_toolkits.mplot3d import art3d [as 别名]
# 或者: from mpl_toolkits.mplot3d.art3d import Line3DCollection [as 别名]
def colored_line_collection(xyz, colors, plot_mode=PlotMode.xy,
linestyles="solid", step=1, alpha=1.):
if len(xyz) / step != len(colors):
raise PlotException(
"color values don't have correct length: %d vs. %d" %
(len(xyz) / step, len(colors)))
x_idx, y_idx, z_idx = plot_mode_to_idx(plot_mode)
xs = [[x_1, x_2]
for x_1, x_2 in zip(xyz[:-1:step, x_idx], xyz[1::step, x_idx])]
ys = [[x_1, x_2]
for x_1, x_2 in zip(xyz[:-1:step, y_idx], xyz[1::step, y_idx])]
if plot_mode == PlotMode.xyz:
zs = [[x_1, x_2]
for x_1, x_2 in zip(xyz[:-1:step, z_idx], xyz[1::step, z_idx])]
segs = [list(zip(x, y, z)) for x, y, z in zip(xs, ys, zs)]
line_collection = art3d.Line3DCollection(segs, colors=colors,
alpha=alpha,
linestyles=linestyles)
else:
segs = [list(zip(x, y)) for x, y in zip(xs, ys)]
line_collection = LineCollection(segs, colors=colors, alpha=alpha,
linestyle=linestyles)
return line_collection
示例2: colored_line_collection
# 需要导入模块: from mpl_toolkits.mplot3d import art3d [as 别名]
# 或者: from mpl_toolkits.mplot3d.art3d import Line3DCollection [as 别名]
def colored_line_collection(xyz, colors, plot_mode=PlotMode.xy,
linestyles="solid"):
if len(xyz) != len(colors):
raise PlotException(
"color values must have same length as xyz data: %d vs. %d" %
(len(xyz), len(colors)))
x_idx, y_idx, z_idx = plot_mode_to_idx(plot_mode)
xs = [[x_1, x_2] for x_1, x_2 in zip(xyz[:-1, x_idx], xyz[1:, x_idx])]
ys = [[x_1, x_2] for x_1, x_2 in zip(xyz[:-1, y_idx], xyz[1:, y_idx])]
if plot_mode == PlotMode.xyz:
zs = [[x_1, x_2] for x_1, x_2 in zip(xyz[:-1, z_idx], xyz[1:, z_idx])]
segs = [list(zip(x, y, z)) for x, y, z in zip(xs, ys, zs)]
line_collection = art3d.Line3DCollection(segs, colors=colors,
linestyles=linestyles)
else:
segs = [list(zip(x, y)) for x, y in zip(xs, ys)]
line_collection = LineCollection(segs, colors=colors,
linestyle=linestyles)
return line_collection
示例3: plot_3d_forest_rover
# 需要导入模块: from mpl_toolkits.mplot3d import art3d [as 别名]
# 或者: from mpl_toolkits.mplot3d.art3d import Line3DCollection [as 别名]
def plot_3d_forest_rover(roverdomain, rectangles, ntraj_points=100):
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection, Line3DCollection
# get the cost of the current trajectory
traj_cost = roverdomain.estimate_cost()
# get points on the current trajectory
traj_points = roverdomain.traj.get_points(np.linspace(0., 1.0, ntraj_points, endpoint=True))
# convert the rectangles into lists of vertices for matplotlib
poly3d, verts, faces = generate_verts(rectangles)
ax = plt.gcf().add_subplot(111, projection='3d')
# plot start and goal
ax.scatter((roverdomain.start[0], roverdomain.goal[0]),
(roverdomain.start[1], roverdomain.goal[1]),
(roverdomain.start[2], roverdomain.goal[2]), c='k')
# plot traj
seg = (zip(traj_points[:-1, :], traj_points[1:, :]))
ax.add_collection3d(Line3DCollection(seg, colors=[(0, 1., 0, 1.)] * len(seg)))
# plot rectangles
ax.add_collection3d(Poly3DCollection(poly3d, facecolors=(0.7, 0.7, 0.7, 1.), linewidth=0.5))
# set limits of axis to be the same as domain
s_range = roverdomain.s_range
ax.set_xlim(s_range[0][0], s_range[1][0])
ax.set_ylim(s_range[0][1], s_range[1][1])
ax.set_zlim(s_range[0][2], s_range[1][2])
示例4: init_artists
# 需要导入模块: from mpl_toolkits.mplot3d import art3d [as 别名]
# 或者: from mpl_toolkits.mplot3d.art3d import Line3DCollection [as 别名]
def init_artists(self, ax, plot_args, plot_kwargs):
line_segments = Line3DCollection(*plot_args, **plot_kwargs)
ax.add_collection(line_segments)
return {'artist': line_segments}
示例5: setGraph
# 需要导入模块: from mpl_toolkits.mplot3d import art3d [as 别名]
# 或者: from mpl_toolkits.mplot3d.art3d import Line3DCollection [as 别名]
def setGraph(self, edges):
"""Set edges of graph visualization - sequence of (i,j) tuples."""
# Only allocate new memory if we need to.
n_edges = len(edges)
if self.graph_edges is None or n_edges != len(self.graph_edges):
self.graph_lines = np.zeros((n_edges, 2, 3))
self.graph_edges = edges
# Lazily construct Matplotlib object for graph.
if self.graph is None:
self.graph = Line3DCollection(self.graph_lines, edgecolor=self.line_color)
self.ax.add_collection(self.graph)
示例6: draw_lines_3d
# 需要导入模块: from mpl_toolkits.mplot3d import art3d [as 别名]
# 或者: from mpl_toolkits.mplot3d.art3d import Line3DCollection [as 别名]
def draw_lines_3d(lines,
axes,
linewidth=1.0,
linestyle='solid',
color='#000000'):
"""Creates an 3D line collection and adds it to the axis.
Parameters
----------
lines : list
Pairs of XYZ coordinates defining start and end points of the lines.
axes : object
Matplotlib axes.
linewidth : float or list of float, optional
Width for the lines.
Default is ``1.0``.
linestyle : str, optional
Matplotlib line style strings.
Default is ``'solid'``.
color : str or list of str, optional
Color of the lines.
Default is black.
Returns
-------
object
The matplotlib line collection object.
"""
n = len(lines)
if isinstance(linewidth, (int, float)):
linewidth = float(linewidth)
linewidth = [linewidth] * n
if isinstance(color, basestring):
color = [color] * n
coll = Line3DCollection(
lines,
linewidths=linewidth,
colors=color,
linestyle=linestyle,
zorder=ZORDER_LINES
)
axes.add_collection(coll)
return coll
# ==============================================================================
# polylines
# ==============================================================================