Пример #1
0
def plot_skeleton_on_axes3d(skel,
                            skel_desc,
                            ax: Axes3D,
                            invert=True,
                            alpha=1.0):
    ax.set_xlabel('x')
    ax.set_ylabel('z')
    ax.set_zlabel('y')

    # NOTE: y and z axes are swapped
    xs = skel.narrow(-1, 0, 1).numpy()
    ys = skel.narrow(-1, 2, 1).numpy()
    zs = skel.narrow(-1, 1, 1).numpy()

    # Correct aspect ratio (https://stackoverflow.com/a/21765085)
    max_range = np.array(
        [xs.max() - xs.min(),
         ys.max() - ys.min(),
         zs.max() - zs.min()]).max() / 2.0
    mid_x = (xs.max() + xs.min()) * 0.5
    mid_y = (ys.max() + ys.min()) * 0.5
    mid_z = (zs.max() + zs.min()) * 0.5
    ax.set_xlim(mid_x - max_range, mid_x + max_range)
    ax.set_ylim(mid_y - max_range, mid_y + max_range)
    ax.set_zlim(mid_z - max_range, mid_z + max_range)
    ax.set_aspect('equal')

    if invert:
        ax.invert_zaxis()

    # Set starting view
    ax.view_init(elev=20, azim=-100)

    get_joint_metadata = _make_joint_metadata_fn(skel_desc)
    for joint_id, joint in enumerate(skel):
        meta = get_joint_metadata(joint_id)
        color = 'magenta'
        if meta['group'] == 'left':
            color = 'blue'
        if meta['group'] == 'right':
            color = 'red'
        parent = skel[meta['parent']]
        offset = parent - joint
        ax.quiver(
            [joint[0]],
            [joint[2]],
            [joint[1]],
            [offset[0]],
            [offset[2]],
            [offset[1]],
            color=color,
            alpha=alpha,
        )

    ax.scatter(xs, ys, zs, color='grey', alpha=alpha)
Пример #2
0
    def plot_moment_vectors(self, ax: Axes3D, sizefactor=1.0):

        for moment in self.get_moments():
            direction = moment.get_direction()
            u, v, w = direction
            length = np.sqrt(u**2 + v**2 + w**2)
            x, y, z = moment.get_position()
            ax.quiver(x,
                      z,
                      y,
                      u,
                      w,
                      v,
                      color='g',
                      length=length * sizefactor,
                      pivot='tail')
Пример #3
0
    def plot_force_vectors(self, ax: Axes3D, sizefactor=0.33):

        for force in self.get_forces():
            direction = force.get_direction()
            u, v, w = direction
            length = np.sqrt(u**2 + v**2 + w**2)
            x, y, z = force.get_position()
            ax.quiver(x,
                      z,
                      y,
                      u,
                      w,
                      v,
                      color='r',
                      length=length * sizefactor,
                      pivot='tip')
Пример #4
0
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
from mpl_toolkits.mplot3d import Axes3D
# %%
tail_location = np.zeros((3, 3))
tip_location = np.asarray([[1, 2, 3], [1.5, 2, 2.5], [2, -2, 1]])

x, y, z = tail_location[:,0], tail_location[:,1], tail_location[:,2]
u, v, w = tip_location[:,0], tip_location[:,1], tip_location[:,2]
# %
# fig, ax = plt.subplots(figsize=(8, 6))
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
print(x,y,z,u,v,w)
Axes3D.quiver(x, y, z, u, v, w)
plt.show()

x, y, z = np.meshgrid(np.arange(0.8, 1, 0.2),
                      np.arange(0.8, 1, 0.2),
                      np.arange(0.8, 1, 0.8))

# %%
from Mediumrare import db_tools
import pandas as pd
conn = db_tools.get_conn()
query = 'SELECT title, blog_url from mediumcleanfull ORDER BY id'
titles = conn.execute(query).fetchall()

df = pd.read_sql(query, conn)
df['channel'] = df.blog_url.map(lambda x: x.split('/')[3])