Skip to content

Commit 104f385

Browse files
committed
Resolve comments on flake8 violations and improve docstrings
1 parent 51784a9 commit 104f385

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

.flake8

+1
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,4 @@ per-file-ignores =
262262
examples/userdemo/connectionstyle_demo.py: E402
263263
examples/userdemo/custom_boxstyle01.py: E402
264264
examples/userdemo/pgf_preamble_sgskip.py: E402
265+
examples/widgets/textbox.py: E402

examples/widgets/textbox.py

+17-14
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
Textbox
44
=======
55
6-
Allowing text input with the Textbox widget.
7-
8-
You can use the Textbox widget to let users interactively provide any text
9-
that needs to be displayed, including formulas. You can use a submit button to
10-
create plots with the given input.
11-
12-
Note to not get confused with
13-
:doc:`/tutorials/text/annotations` and
14-
:doc:`/gallery/recipes/placing_text_boxes`, both of which are static elements.
6+
The Textbox widget lets users interactively provide text input, including
7+
formulas. In this example, the plot is updated using the `.on_submit` method.
8+
This method triggers the execution of the `submit` function when the user
9+
presses enter in the textbox or leaves the textbox.
10+
11+
Note: The `Textbox` widget is different from the following static elements:
12+
:doc:`/tutorials/text/annotations` and
13+
:doc:`/gallery/recipes/placing_text_boxes`.
1514
"""
1615

1716
import numpy as np
@@ -22,13 +21,17 @@
2221
t = np.arange(-2.0, 2.0, 0.001)
2322
s = t ** 2
2423
initial_text = "t ** 2"
25-
l, = plt.plot(t, s, lw=2)
24+
l, = plt.plot(t, s, lw=2) # make a plot for the math expression "t ** 2"
25+
2626

27+
def submit(expression):
28+
"""
29+
Update the plotted function to the new math *expression*.
2730
28-
def submit(text):
29-
# user can enter a new math expression that uses "t" as its independent
30-
# variable. The plot refreshes on entering. Example: try "t ** 3"
31-
ydata = eval(text)
31+
*expession* is a string using "t" as its independent variable, e.g.
32+
"t ** 3".
33+
"""
34+
ydata = eval(expression)
3235
l.set_ydata(ydata)
3336
ax.set_ylim(np.min(ydata), np.max(ydata))
3437
plt.draw()

0 commit comments

Comments
 (0)