私は python と matplotlib にまったく慣れていないので、このウェブサイトは私を大いに助けてくれました。しかし、この主題について完全な答えを見つけることができませんでした。
matplotlib を使用して 3D プロットのポイントに注釈を付けたいので、いくつかの調査の後、このコードの平和を見つけました: Matplotlib: Annotating a 3D scatter plot
import pylab
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d import proj3d
fig = pylab.figure()
ax = fig.add_subplot(111, projection = '3d')
x = y = z = [1, 2, 3]
sc = ax.scatter(x,y,z)
# now try to get the display coordinates of the first point
x2, y2, _ = proj3d.proj_transform(1,1,1, ax.get_proj())
label = pylab.annotate(
"this",
xy = (x2, y2), xytext = (-20, 20),
textcoords = 'offset points', ha = 'right', va = 'bottom',
bbox = dict(boxstyle = 'round,pad=0.5', fc = 'yellow', alpha = 0.5),
arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'))
def update_position(e):
x2, y2, _ = proj3d.proj_transform(1,1,1, ax.get_proj())
label.xy = x2,y2
label.update_positions(fig.canvas.renderer)
fig.canvas.draw()
fig.canvas.mpl_connect('button_release_event', update_position)
pylab.show()
しかし、問題は、このコードで最後のラベルのみを更新することに成功したことです。 update_position(e) 関数でいくつかのループを実行しようとしました。しかし、私は確かに何かが欠けています。これまでは Axes3D.text(x, y, z, s, zdir) 関数を使用していましたが、見栄えがよくありません。
ありがとう !