def mplArt_from_shape( shapes, in3d=False, z=0.0, zdir='z' ) :
    """
    can be made an Arc with:
    matplotlib.patches.Arc(xy, width, height, angle=0.0, theta1=0.0, theta2=360.0, **kwargs)
    for circle width=height=R
    """
    """
    > dictionary with keys 'dashed' (for edge drawing) and 'solid' (for the geometry)
    > shape has type ( 'arc' or 'segment' ), and relevent details
    """
    Art = []
    for style in [ 'solid', 'dashed' ] :
        if not style in shapes : continue
        
        shape = shapes[style]
        if shape.type == 'arc' :
            piece = mpl.patches.Arc( shape.center, 2*shape.radius, 2*shape.radius,
                                   angle = 0.0,
                                   theta1 = 180.0 * shape.theta1 / np.pi,
                                   theta2 = 180.0 * shape.theta2 / np.pi,
                                   linestyle=style, color='b' )
            if in3d : piece = art3d.patch_2d_to_3d( piece, z=z, zdir=zdir )
            
        elif shape.type == 'segment' :
            piece = mpl.lines.Line2D( shape.xdata, shape.ydata, linestyle=style )
            if in3d : piece = art3d.line_2d_to_3d( piece, zs=z, zdir=zdir )
            
        Art.append(piece)
    return Art
def art_convert3d( art, z=0.0, zdir='z' ) :
    """ doesn't effing work """
    if isinstance( art, mpl.lines.Line2D ) :
        new_art = art3d.line_2d_to_3d( art, zs=z, zdir=zdir )
    elif isinstance( art, mpl.patches.Patch ) :
        new_art = art3d.patch_2d_to_3d( art, z=z, zdir=zdir )
    else : raise Exception('not a valid type of art')
    
    return new_art
def mplArt_from_shape( shapes, in3d=False, z=0.0, zdir='z' ) :
    Art = []
    for style in [ 'solid', 'dashed' ] :
        if not style in shapes : continue
        
        shape = shapes[style]
        if shape.type == 'arc' :
            piece = mpl.patches.Arc( shape.center, 2*shape.radius, 2*shape.radius,
                                   angle = 0.0,
                                   theta1 = 180.0 * shape.theta1 / np.pi,
                                   theta2 = 180.0 * shape.theta2 / np.pi,
                                   linestyle=style, color='b' )
            if in3d : piece = art3d.patch_2d_to_3d( piece, z=z, zdir=zdir )
            
        elif shape.type == 'segment' :
            piece = mpl.lines.Line2D( shape.xdata, shape.ydata, linestyle=style )
            if in3d : piece = art3d.line_2d_to_3d( piece, zs=z, zdir=zdir )
            
        Art.append(piece)
    return Art
示例#4
0
 def _draw_line(self, X, Y, *args, z: float = 0, **kwargs):
     artist = super()._draw_line(np.array(X), np.array(Y), *args, **kwargs)
     art3d.line_2d_to_3d(artist, zs=z)
     return artist
示例#5
0
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import art3d

mpl.rcParams['legend.fontsize'] = 10

x = [0, 1]
y = [0, 1]
z = [0, 1]

fig = plt.figure()
ax = fig.gca(projection='3d')

line = ax.plot(x, y, z, label='parametric curve')[0]
art3d.line_2d_to_3d(line)
line.set_data_3d([0,2], [0,2], [0,2])
ax.legend()

plt.show()