300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > python三维图形注释_python – Matplotlib:注释3D散点图

python三维图形注释_python – Matplotlib:注释3D散点图

时间:2022-07-27 02:54:53

相关推荐

python三维图形注释_python – Matplotlib:注释3D散点图

计算点的2D位置,并使用它创建注释。如果您需要与图形交互,则可以在鼠标释放时重新计算位置。

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()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。