在 Python 中用交互式图形绘制算法

发布于 2025-01-15 01:23:18 字数 432 浏览 4 评论 0原文

我想要可视化一种算法的效果,该算法采用 2d 向量作为输入,并提供 2d 向量数组作为输出(其中数组在索引 k 处具有第 k 次迭代值)。

我希望它的工作方式是在左侧绘制一定范围的数字的二维图来表示输入向量,并在右侧绘制一个类似的二维图来绘制连接的输出向量。

对于单个输入点,我知道我可以使用 matplotlib 的 plt.subplots() 来完成此操作,就像文档中松散改编的示例一样:

fig, axs = plt.subplots(2)
fig.suptitle('Vertically stacked subplots')
axs[0].plot(in_x, in_y)
axs[1].plot(out_array_x, out_array_y, 'o-')

但我想做的是移动输入侧的点使用鼠标并以交互方式获得右侧的结果输出。这怎么可能做到呢?

I want to visualise the effect of an algorithm that takes a 2d vector as input and delivers an array of 2d vectors as output (where the array has the k-th iteration value at index k).

The way I would like this to work is by having a 2d plot of a certain range of numbers on the left that represents the input vector, and a similar 2d plot on the right that plots the connected output vectors.

For an individual input point I know I could do this with matplotlib's plt.subplots() like this loosely adapted example from the documentation:

fig, axs = plt.subplots(2)
fig.suptitle('Vertically stacked subplots')
axs[0].plot(in_x, in_y)
axs[1].plot(out_array_x, out_array_y, 'o-')

But what I would like to do is to move the point on the input side with the mouse and get the resulting output on the right interactively. How could this be done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文