本文整理匯總了Python中mpl_toolkits.mplot3d.Axes3D.name方法的典型用法代碼示例。如果您正苦於以下問題:Python Axes3D.name方法的具體用法?Python Axes3D.name怎麽用?Python Axes3D.name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mpl_toolkits.mplot3d.Axes3D
的用法示例。
在下文中一共展示了Axes3D.name方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: render_sdf
# 需要導入模塊: from mpl_toolkits.mplot3d import Axes3D [as 別名]
# 或者: from mpl_toolkits.mplot3d.Axes3D import name [as 別名]
def render_sdf(obj_, object_name_):
plt.figure()
# ax = h.add_subplot(111, projection='3d')
# surface_points = np.where(np.abs(sdf.sdf_values) < thresh)
# surface_points = np.array(surface_points)
# surface_points = surface_points[:, np.random.choice(surface_points[0].size, 3000, replace=True)]
# # from IPython import embed; embed()
surface_points = obj_.sdf.surface_points()[0]
surface_points = np.array(surface_points)
ind = np.random.choice(np.arange(len(surface_points)), 1000)
x = surface_points[ind, 0]
y = surface_points[ind, 1]
z = surface_points[ind, 2]
ax = plt.gca(projection=Axes3D.name)
ax.scatter(x, y, z, '.', s=np.ones_like(x) * 0.3, c='b')
ax.set_xlim3d(0, obj_.sdf.dims_[0])
ax.set_ylim3d(0, obj_.sdf.dims_[1])
ax.set_zlim3d(0, obj_.sdf.dims_[2])
plt.title(object_name_)
plt.show()
示例2: plot
# 需要導入模塊: from mpl_toolkits.mplot3d import Axes3D [as 別名]
# 或者: from mpl_toolkits.mplot3d.Axes3D import name [as 別名]
def plot(self):
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.gca(projection=Axes3D.name)
# ax.set_aspect("equal")
flt = numpy.vectorize(float)
pts = flt(self.points)
wgs = flt(self.weights)
for p, w in zip(pts, wgs):
# <https://en.wikipedia.org/wiki/Spherical_cap>
w *= 4 * numpy.pi
theta = numpy.arccos(1.0 - abs(w) / (2 * numpy.pi))
color = "tab:blue" if w >= 0 else "tab:red"
_plot_spherical_cap_mpl(ax, p, theta, color)
ax.set_axis_off()
示例3: visualize_voxels
# 需要導入模塊: from mpl_toolkits.mplot3d import Axes3D [as 別名]
# 或者: from mpl_toolkits.mplot3d.Axes3D import name [as 別名]
def visualize_voxels(voxels, out_file=None, show=False):
r''' Visualizes voxel data.
Args:
voxels (tensor): voxel data
out_file (string): output file
show (bool): whether the plot should be shown
'''
# Use numpy
voxels = np.asarray(voxels)
# Create plot
fig = plt.figure()
ax = fig.gca(projection=Axes3D.name)
voxels = voxels.transpose(2, 0, 1)
ax.voxels(voxels, edgecolor='k')
ax.set_xlabel('Z')
ax.set_ylabel('X')
ax.set_zlabel('Y')
ax.view_init(elev=30, azim=45)
if out_file is not None:
plt.savefig(out_file)
if show:
plt.show()
plt.close(fig)
示例4: plot_rand_meth_samples
# 需要導入模塊: from mpl_toolkits.mplot3d import Axes3D [as 別名]
# 或者: from mpl_toolkits.mplot3d.Axes3D import name [as 別名]
def plot_rand_meth_samples(generator):
"""Plot the samples of the rand meth class."""
norm, rad = norm_rad(generator._cov_sample)
fig = plt.figure(figsize=(10, 4))
if generator.model.dim == 3:
ax = fig.add_subplot(121, projection=Axes3D.name)
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
x = np.outer(np.cos(u), np.sin(v))
y = np.outer(np.sin(u), np.sin(v))
z = np.outer(np.ones(np.size(u)), np.cos(v))
ax.plot_surface(x, y, z, rstride=4, cstride=4, color="b", alpha=0.1)
ax.scatter(norm[0], norm[1], norm[2])
elif generator.model.dim == 2:
ax = fig.add_subplot(121)
u = np.linspace(0, 2 * np.pi, 100)
x = np.cos(u)
y = np.sin(u)
ax.plot(x, y, color="b", alpha=0.1)
ax.scatter(norm[0], norm[1])
ax.set_aspect("equal")
else:
ax = fig.add_subplot(121)
ax.bar(-1, np.sum(np.isclose(norm, -1)), color="C0")
ax.bar(1, np.sum(np.isclose(norm, 1)), color="C0")
ax.set_xticks([-1, 1])
ax.set_xticklabels(("-1", "1"))
ax.set_title("Direction sampling")
ax = fig.add_subplot(122)
x = np.linspace(0, 10 / generator.model.integral_scale)
y = generator.model.spectral_rad_pdf(x)
ax.plot(x, y, label="radial spectral density")
sample_in = np.sum(rad <= np.max(x))
ax.hist(rad[rad <= np.max(x)], bins=sample_in // 50, density=True)
ax.set_xlim([0, np.max(x)])
ax.set_title("Radius samples shown {}/{}".format(sample_in, len(rad)))
ax.legend()
fig.show()
示例5: get_volume_views
# 需要導入模塊: from mpl_toolkits.mplot3d import Axes3D [as 別名]
# 或者: from mpl_toolkits.mplot3d.Axes3D import name [as 別名]
def get_volume_views(volume, save_dir, n_itr):
if not os.path.exists(save_dir):
os.makedirs(save_dir)
volume = volume.squeeze().__ge__(0.5)
fig = plt.figure()
ax = fig.gca(projection=Axes3D.name)
ax.set_aspect('equal')
ax.voxels(volume, edgecolor="k")
save_path = os.path.join(save_dir, 'voxels-%06d.png' % n_itr)
plt.savefig(save_path, bbox_inches='tight')
plt.close()
return cv2.imread(save_path)
示例6: __init__
# 需要導入模塊: from mpl_toolkits.mplot3d import Axes3D [as 別名]
# 或者: from mpl_toolkits.mplot3d.Axes3D import name [as 別名]
def __init__(self, name, weights, points, azimuthal_polar, degree, source):
self.domain = "U3"
self.name = name
self.degree = degree
self.source = source
if weights.dtype == numpy.float64:
self.weights = weights
else:
assert weights.dtype in [numpy.dtype("O"), numpy.int_]
self.weights = weights.astype(numpy.float64)
self.weights_symbolic = weights
if points.dtype == numpy.float64:
self.points = points
else:
assert points.dtype in [numpy.dtype("O"), numpy.int_]
self.points = points.astype(numpy.float64)
self.points_symbolic = points
if azimuthal_polar.dtype == numpy.float64:
self.azimuthal_polar = azimuthal_polar
else:
assert azimuthal_polar.dtype in [numpy.dtype("O"), numpy.int_]
self.azimuthal_polar = azimuthal_polar.astype(numpy.float64)
self.azimuthal_polar_symbolic = azimuthal_polar
示例7: visualize_pointcloud
# 需要導入模塊: from mpl_toolkits.mplot3d import Axes3D [as 別名]
# 或者: from mpl_toolkits.mplot3d.Axes3D import name [as 別名]
def visualize_pointcloud(points, normals=None,
out_file=None, show=False):
r''' Visualizes point cloud data.
Args:
points (tensor): point data
normals (tensor): normal data (if existing)
out_file (string): output file
show (bool): whether the plot should be shown
'''
# Use numpy
points = np.asarray(points)
# Create plot
fig = plt.figure()
ax = fig.gca(projection=Axes3D.name)
ax.scatter(points[:, 2], points[:, 0], points[:, 1])
if normals is not None:
ax.quiver(
points[:, 2], points[:, 0], points[:, 1],
normals[:, 2], normals[:, 0], normals[:, 1],
length=0.1, color='k'
)
ax.set_xlabel('Z')
ax.set_ylabel('X')
ax.set_zlabel('Y')
ax.set_xlim(-0.5, 0.5)
ax.set_ylim(-0.5, 0.5)
ax.set_zlim(-0.5, 0.5)
ax.view_init(elev=30, azim=45)
if out_file is not None:
plt.savefig(out_file)
if show:
plt.show()
plt.close(fig)
示例8: show_straights
# 需要導入模塊: from mpl_toolkits.mplot3d import Axes3D [as 別名]
# 或者: from mpl_toolkits.mplot3d.Axes3D import name [as 別名]
def show_straights(cs):
from mpl_toolkits.mplot3d import Axes3D
# Some straight lines in XYZ
t = numpy.linspace(0.0, 1.0, 101)
n = 10
fig = plt.figure()
ax = fig.gca(projection=Axes3D.name)
# ax.set_aspect('equal')
for _ in range(n):
s1 = numpy.random.rand(3)
s1 /= numpy.linalg.norm(s1)
s1 *= 100
line = numpy.outer(s1, t)
cs_line = cs.from_xyz100(line)
# ax.plot(
# [cs_line[0][0], cs_line[0][-1]],
# [cs_line[1][0], cs_line[1][-1]],
# [cs_line[2][0], cs_line[2][-1]],
# color='0.5'
# )
ax.plot(*cs_line)
ax.set_xlabel(cs.labels[0])
ax.set_ylabel(cs.labels[1])
ax.set_zlabel(cs.labels[2])
plt.show()
示例9: show
# 需要導入模塊: from mpl_toolkits.mplot3d import Axes3D [as 別名]
# 或者: from mpl_toolkits.mplot3d.Axes3D import name [as 別名]
def show(self):
"""
"""
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot as plt
fig = plt.figure()
ax = fig.gca(projection=Axes3D.name)
# "It is not currently possible to manually set the aspect on 3D axes"
# plt.axis("equal")
if self._circumcenters is None:
self._compute_cell_circumcenters()
X = self.node_coords
for cell_id in range(len(self.cells["nodes"])):
cc = self._circumcenters[cell_id]
#
x = X[self.node_face_cells[..., [cell_id]]]
face_ccs = compute_triangle_circumcenters(x, self.ei_dot_ei, self.ei_dot_ej)
# draw the face circumcenters
ax.plot(
face_ccs[..., 0].flatten(),
face_ccs[..., 1].flatten(),
face_ccs[..., 2].flatten(),
"go",
)
# draw the connections
# tet circumcenter---face circumcenter
for face_cc in face_ccs:
ax.plot(
[cc[..., 0], face_cc[..., 0]],
[cc[..., 1], face_cc[..., 1]],
[cc[..., 2], face_cc[..., 2]],
"b-",
)
return
示例10: plot
# 需要導入模塊: from mpl_toolkits.mplot3d import Axes3D [as 別名]
# 或者: from mpl_toolkits.mplot3d.Axes3D import name [as 別名]
def plot(fn, random_state):
"""
Implements plotting of 2D functions generated by FunctionGenerator
:param fn: Instance of FunctionGenerator
"""
import numpy as np
from l2l.matplotlib_ import plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
fig = plt.figure()
ax = fig.gca(projection=Axes3D.name)
# Make data.
X = np.arange(fn.bound[0], fn.bound[1], 0.05)
Y = np.arange(fn.bound[0], fn.bound[1], 0.05)
XX, YY = np.meshgrid(X, Y)
Z = [fn.cost_function([x, y], random_state=random_state) for x, y in zip(XX.ravel(), YY.ravel())]
Z = np.array(Z).reshape(XX.shape)
# Plot the surface.
surf = ax.plot_surface(XX, YY, Z, cmap=cm.coolwarm, linewidth=0, antialiased=False)
# Customize the z axis.
# ax.set_zlim(-1.01, 1.01)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
W = np.where(Z == np.min(Z))
ax.set(title='Min value is %.2f at (%.2f, %.2f)' % (np.min(Z), X[W[0]], Y[W[1]]))
# Add a color bar which maps values to colors.
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.savefig('function.png')
plt.show()
示例11: plot_best_state
# 需要導入模塊: from mpl_toolkits.mplot3d import Axes3D [as 別名]
# 或者: from mpl_toolkits.mplot3d.Axes3D import name [as 別名]
def plot_best_state(train_state):
X_train, y_train, X_test, y_test, best_y, best_ystd = train_state.packed_data()
y_dim = best_y.shape[1]
# Regression plot
if X_test.shape[1] == 1:
idx = np.argsort(X_test[:, 0])
X = X_test[idx, 0]
plt.figure()
for i in range(y_dim):
if y_train is not None:
plt.plot(X_train[:, 0], y_train[:, i], "ok", label="Train")
if y_test is not None:
plt.plot(X, y_test[idx, i], "-k", label="True")
plt.plot(X, best_y[idx, i], "--r", label="Prediction")
if best_ystd is not None:
plt.plot(
X, best_y[idx, i] + 2 * best_ystd[idx, i], "-b", label="95% CI"
)
plt.plot(X, best_y[idx, i] - 2 * best_ystd[idx, i], "-b")
plt.xlabel("x")
plt.ylabel("y")
plt.legend()
elif X_test.shape[1] == 2:
for i in range(y_dim):
plt.figure()
ax = plt.axes(projection=Axes3D.name)
ax.plot3D(X_test[:, 0], X_test[:, 1], best_y[:, i], ".")
ax.set_xlabel("$x_1$")
ax.set_ylabel("$x_2$")
ax.set_zlabel("$y_{}$".format(i + 1))
# Residual plot
if y_test is not None:
plt.figure()
residual = y_test[:, 0] - best_y[:, 0]
plt.plot(best_y[:, 0], residual, "o", zorder=1)
plt.hlines(0, plt.xlim()[0], plt.xlim()[1], linestyles="dashed", zorder=2)
plt.xlabel("Predicted")
plt.ylabel("Residual = Observed - Predicted")
plt.tight_layout()
if best_ystd is not None:
plt.figure()
for i in range(y_dim):
plt.plot(X_test[:, 0], best_ystd[:, i], "-b")
plt.plot(
X_train[:, 0],
np.interp(X_train[:, 0], X_test[:, 0], best_ystd[:, i]),
"ok",
)
plt.xlabel("x")
plt.ylabel("std(y)")