How to put the text with rigorous orientation on 3d surface?

21 views Asked by At

I'm trying to plot 3d surface with text.

For example let's consider surface described by eq. z = 1:

import matplotlib.pyplot as plt
import numpy as np

x = np.array([0, 1])
y = np.array([0, 1])

X,Y = np.meshgrid(x,y)
Z = np.ones((2,2))

# Create a 3D plot
fig = plt.figure()
ax = fig.add_subplot(projection='3d')

# Plot the surface
ax.plot_surface(X, Y, Z, alpha=0.7)

# Set the labels
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

# Show the plot
plt.show()

enter image description here

Further I would like to add text to this surface at the coordinate (0.5,0.5,1). Text should printed strictly on this surface and oriented at an angle of 45 like that:

enter image description here

Unfortunately, I haven't found any satisfactory solution of this problem in matplotlib functional. I tried simple ax.text(0.5,0.5,1, "Text", fontsize = 20), but it's far from the result I'm trying to achieve. (Text nether belongs to the surface nor has the proper orientation, see below)

enter image description here

Please, help me!

0

There are 0 answers