python - matplotlib,ipywidgets - 如何更改箭袋对象的位置?
问题描述
我想根据来自 ipywidgets 滚动的交互输入来更改箭袋(或箭头)对象的位置。
这是我尝试过的:
%matplotlib notebook
from ipywidgets import *
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse, Arrow
fig = plt.figure(figsize=[6,6])
ax = fig.add_subplot(1, 1, 1)
x_ar1 = -5 #object distance
dy_ar1 = 2 #boject heightX
object1 = plt.quiver(x_ar1, 0, 0, dy_ar1, angles='xy', scale_units='xy', scale=1)
ax.add_artist(object1)
#mark axis
x_axis, = ax.plot([-10, 10], [0, 0], lw=1, c='k')
plt.xlim([-10,10])
plt.ylim([-5,5])
def update(x = -5, y = 2):
x_ar1 = x
dy_ar1 = y
object1.X = x_ar1
object1.V = dy_ar1
fig.canvas.draw_idle()
interact(update, x=(-6,6,0.1), y = (-2,2,0.1))
即使代码适用于箭袋的高度 ( object1.V
),它也不适用于对象的放置 ( object1.X
)。我也看不到任何set_xy
可用的功能。有谁知道我在这里想念什么?
解决方案
我认为 matplotlib 目前不允许这样做。见https://matplotlib.org/devdocs/api/_as_gen/matplotlib.quiver.Quiver.html?highlight=quiver#matplotlib.quiver.Quiver
唯一的 API 方法是 set_UVC(),可以用来改变箭头的大小、方向和颜色;当类被实例化时,它们的位置是固定的。这种方法可能在动画中很有用。
Matplotlib 上有一个开放的功能请求:https ://github.com/matplotlib/matplotlib/issues/11790
推荐阅读
- google-oauth - 具有谷歌联合身份的 Aws Cognito:使用最后一个用户登录
- c++ - c++11中的随机字节生成
- apache-spark-sql - 使用直线连接到 spark thift 服务器时无法加载哨兵配置
- asp.net-mvc - 快速报告预览 - C# MVC
- angular - Ionic:promise 是如何工作的?
- python-2.7 - 压缩 .npy 数据以节省磁盘空间
- data-warehouse - 维度模型 VS 非归一化模型
- sql - 状态的平均持续时间 - 差距和岛屿
- python - 在 Paramiko 中计算文件传输的剩余时间
- python - Streamlabs API 405 响应代码