軸にラベルを付ける
text3d
関数を使用して手動で軸にラベルを付けます。この関数は、テキストの位置、表示するテキスト、三次元として扱う軸、およびその他のパラメータを受け取ります。
def text3d(ax, xyz, s, zdir="z", size=None, angle=0, usetex=False, **kwargs):
"""
Plots the string *s* on the axes *ax*, with position *xyz*, size *size*,
and rotation angle *angle*. *zdir* gives the axis which is to be treated as
the third dimension. *usetex* is a boolean indicating whether the string
should be run through a LaTeX subprocess or not. Any additional keyword
arguments are forwarded to `.transform_path`.
Note: zdir affects the interpretation of xyz.
"""
x, y, z = xyz
if zdir == "y":
xy1, z1 = (x, z), y
elif zdir == "x":
xy1, z1 = (y, z), x
else:
xy1, z1 = (x, y), z
text_path = TextPath((0, 0), s, size=size, usetex=usetex)
trans = Affine2D().rotate(angle).translate(xy1[0], xy1[1])
p1 = PathPatch(trans.transform_path(text_path), **kwargs)
ax.add_patch(p1)
art3d.pathpatch_2d_to_3d(p1, z=z1, zdir=zdir)
text3d(ax, (4, -2, 0), "X 軸", zdir="z", size=.5, usetex=False,
ec="none", fc="k")
text3d(ax, (12, 4, 0), "Y 軸", zdir="z", size=.5, usetex=False,
angle=np.pi / 2, ec="none", fc="k")
text3d(ax, (12, 10, 4), "Z 軸", zdir="y", size=.5, usetex=False,
angle=np.pi / 2, ec="none", fc="k")