问题描述
TextBox 标签的默认位置在其左侧,如图所示。我想把标签放在盒子下面。这可能吗?
示例代码和图像取自 Matplotlib docs。
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import TextBox
fig,ax = plt.subplots()
fig.subplots_adjust(bottom=0.2)
t = np.arange(-2.0,2.0,0.001)
l,= ax.plot(t,np.zeros_like(t),lw=2)
def submit(expression):
"""
Update the plotted function to the new math *expression*.
*expression* is a string using "t" as its independent variable,e.g.
"t ** 3".
"""
ydata = eval(expression)
l.set_ydata(ydata)
ax.relim()
ax.autoscale_view()
plt.draw()
axBox = fig.add_axes([0.1,0.05,0.8,0.075])
text_Box = TextBox(axBox,"Evaluate")
text_Box.on_submit(submit)
text_Box.set_val("t ** 2") # Trigger `submit` with the initial string.
plt.show()