日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

python+matplotlib實現(xiàn)鼠標(biāo)移動三角形高亮及索引顯示

系統(tǒng) 1950 0

Trifinder事件實例

實例展示Trifinder對象對的使用。當(dāng)鼠標(biāo)移動到一個被分割的三角形上,這個三角形高亮顯示,并且它的標(biāo)簽在圖標(biāo)題顯示。

展示下演示結(jié)果:

python+matplotlib實現(xiàn)鼠標(biāo)移動三角形高亮及索引顯示_第1張圖片

完整代碼:

            
import matplotlib.pyplot as plt
from matplotlib.tri import Triangulation
from matplotlib.patches import Polygon
import numpy as np


def update_polygon(tri):
  if tri == -1:
    points = [0, 0, 0]
  else:
    points = triang.triangles[tri]
  xs = triang.x[points]
  ys = triang.y[points]
  polygon.set_xy(list(zip(xs, ys)))


def motion_notify(event):
  if event.inaxes is None:
    tri = -1
  else:
    tri = trifinder(event.xdata, event.ydata)
  update_polygon(tri)
  plt.title('In triangle %i' % tri)
  event.canvas.draw()


# Create a Triangulation.
n_angles = 16
n_radii = 5
min_radius = 0.25
radii = np.linspace(min_radius, 0.95, n_radii)
angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False)
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
angles[:, 1::2] += np.pi / n_angles
x = (radii*np.cos(angles)).flatten()
y = (radii*np.sin(angles)).flatten()
triang = Triangulation(x, y)
triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1),
             y[triang.triangles].mean(axis=1))
        < min_radius)

# Use the triangulation's default TriFinder object.
trifinder = triang.get_trifinder()

# Setup plot and callbacks.
plt.subplot(111, aspect='equal')
plt.triplot(triang, 'bo-')
polygon = Polygon([[0, 0], [0, 0]], facecolor='y') # dummy data for xs,ys
update_polygon(-1)
plt.gca().add_patch(polygon)
plt.gcf().canvas.mpl_connect('motion_notify_event', motion_notify)
plt.show()
          

總結(jié)

本文所示是一個Python+matplotlib實現(xiàn)的簡單實例,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 武平县| 郸城县| 五莲县| 安丘市| 柞水县| 阳城县| 疏勒县| 工布江达县| 昌宁县| 永定县| 昌江| 东乡| 安岳县| 诏安县| 谢通门县| 邳州市| 绥化市| 昌都县| 中牟县| 麦盖提县| 兴宁市| 陵水| 弥渡县| 巴里| 昭通市| 平罗县| 尚志市| 资中县| 博白县| 嘉峪关市| 宽甸| 城市| 岢岚县| 中方县| 江口县| 大理市| 宿迁市| 吕梁市| 谷城县| 秦皇岛市| 黑龙江省|