-1
メインプロットのマウスホバーの現在のX値に対応する補足プロットでデータをプロットしたかったのです。マウスを別のプロットに移動するようにプロットを更新するにはどうすればよいですか?
私は
残念ながらimport math
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(dpi=100, figsize=(5, 5))
x = np.arange(0, 6, 0.1)
plt.plot(x, np.sin(x), 'r')
fig2, ax2 = plt.subplots(dpi=100, figsize=(5, 5))
def plot_ray(angle, y):
circle = plt.Circle((0, 0), 1, color='b', fill=False)
length = y/math.sin(angle)
line = plt.Line2D([0, length * math.cos(angle)], [0, length * math.sin(angle)])
ax2.clear()
ax2.set_xlim(-2, 2)
ax2.set_ylim(-2, 2)
ax2.add_artist(circle)
ax2.add_artist(line)
def mouse_move(event):
x = event.xdata
y = event.ydata
if x is not None and y is not None:
angle = x
plot_ray(angle, y)
cid = fig.canvas.mpl_connect('motion_notify_event', mouse_move)
plt.show(block=True)
をコード化され、ax2
はunpredicatble動作します。 fig2
ウィンドウをクリックするまで、マウスをホバーしている間は更新されません。またはpycharmでブレークポイントを設定または解除するまで、更新されません。正しい動作をコーディングする方法
?
[mcve]を読み、それに応じて質問を更新してください。問題を再現するために必要な重要な部分を残しておけば、他の人がその問題を理解するのを助けないため、回答を得る手助けをしません。 – ImportanceOfBeingErnest
@ImportanceOfBeingErnest私の更新をご覧ください – Dims