文本(更改位置)上的matplotlib小部件滑块

时间:2018-08-02 15:47:02

标签: object matplotlib text widget slider

我想打印一个文本,并且当d_in滑块更改时,该文本应以我的椭圆(Spiegel)沿x方向移动。

from numpy import pi, sin
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button, RadioButtons
from matplotlib.patches import Ellipse
from scipy.optimize import fsolve
import pylab


axis_color = 'lightgoldenrodyellow'
#variable
d_in=80

fig = plt.figure(figsize=(12,6))
ax = fig.add_subplot(111)
fig.subplots_adjust(left=0.25, bottom=0.35)
x = np.arange(0.0, 300, 0.01)


# object ellipse
Spiegel = Ellipse(xy=(d_in, 0), width=2, height=73.2,
                        edgecolor='black', fc='#808080', lw=1)
ax.add_patch(Spiegel)


#Draw d_in slider
d_in_slider_ax = fig.add_axes([0.25, 0.1, 0.65, 0.03], axisbg=axis_color)
d_in_slider = Slider(d_in_slider_ax, 'd_in', 1, 150, valinit=d_in)

def update(val):
Spiegel.center = (val,0)
d_in_slider.on_changed(update)

#axis range
ax.set_xlim([0, 300])
ax.set_ylim([-40, 40])

plt.show()

如何告诉滑块更改文本的位置?它的定义不像椭圆形。

谢谢

0 个答案:

没有答案