Draw flat objects in 3D plot
Circle
,
from
matplotlib.text
import
from
matplotlib.transforms
import
import
mpl_toolkits.mplot3d.art3d
as
art3d
def
text3d
(
,
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
=
((
0
,
0
),
s
,
size
=
size
,
usetex
=
usetex
)
trans
=
()
.
rotate
(
angle
)
.
translate
(
xy1
[
0
],
xy1
[
1
])
p1
=
(
trans
.
transform_path
(
text_path
),
**
kwargs
)
(
p1
)
(
p1
,
z
=
z1
,
zdir
=
zdir
)
=
()
=
(
projection
=
'3d'
)
=
((
5
,
5
),
3
)
(
)
(
,
z
=
0
,
zdir
=
"x"
)
text3d
(
,
(
4
,
-
2
,
0
),
"X-axis"
,
zdir
=
"z"
,
size
=
.5
,
usetex
=
False
,
ec
=
"none"
,
fc
=
"k"
)
text3d
(
,
(
12
,
4
,
0
),
"Y-axis"
,
zdir
=
"z"
,
size
=
.5
,
usetex
=
False
,
angle
=
/
2
,
ec
=
"none"
,
fc
=
"k"
)
text3d
(
,
(
12
,
10
,
4
),
"Z-axis"
,
zdir
=
"y"
,
size
=
.5
,
usetex
=
False
,
angle
=
/
2
,
ec
=
"none"
,
fc
=
"k"
)
text3d
(
,
(
1
,
5
,
0
),
r
"$\displaystyle G_{\mu\nu} + \Lambda g_{\mu\nu} = "
r
"\frac{8\pi G}{c^4} T_{\mu\nu} $"
,
zdir
=
"z"
,
size
=
1
,
usetex
=
True
,
ec
=
"none"
,
fc
=
"k"
)
(
0
,
10
)
(
0
,
10
)
(
0
,
10
)
()