From 51784a9bb3cb279f663eeb2b07ed9a64df54012d Mon Sep 17 00:00:00 2001 From: chrissshe Date: Mon, 17 Feb 2020 19:35:42 -0800 Subject: [PATCH 1/3] add more comments. add a reference section --- examples/widgets/textbox.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/examples/widgets/textbox.py b/examples/widgets/textbox.py index b3c786014b6c..1f233fbd6594 100644 --- a/examples/widgets/textbox.py +++ b/examples/widgets/textbox.py @@ -5,9 +5,13 @@ Allowing text input with the Textbox widget. -You can use the Textbox widget to let users provide any text that needs to be -displayed, including formulas. You can use a submit button to create plots -with the given input. +You can use the Textbox widget to let users interactively provide any text +that needs to be displayed, including formulas. You can use a submit button to +create plots with the given input. + +Note to not get confused with +:doc:`/tutorials/text/annotations` and +:doc:`/gallery/recipes/placing_text_boxes`, both of which are static elements. """ import numpy as np @@ -22,7 +26,9 @@ def submit(text): - ydata = eval(text) + # user can enter a new math expression that uses "t" as its independent + # variable. The plot refreshes on entering. Example: try "t ** 3" + ydata = eval(text) l.set_ydata(ydata) ax.set_ylim(np.min(ydata), np.max(ydata)) plt.draw() @@ -32,3 +38,15 @@ def submit(text): text_box.on_submit(submit) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +from matplotlib.widgets import TextBox From 104f385b026604efaa20b8d9cdad51360ae04a88 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 18 Feb 2020 18:49:58 -0800 Subject: [PATCH 2/3] Resolve comments on flake8 violations and improve docstrings --- .flake8 | 1 + examples/widgets/textbox.py | 31 +++++++++++++++++-------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.flake8 b/.flake8 index 3bbcf1ded796..68b0c555fd0a 100644 --- a/.flake8 +++ b/.flake8 @@ -262,3 +262,4 @@ per-file-ignores = examples/userdemo/connectionstyle_demo.py: E402 examples/userdemo/custom_boxstyle01.py: E402 examples/userdemo/pgf_preamble_sgskip.py: E402 + examples/widgets/textbox.py: E402 diff --git a/examples/widgets/textbox.py b/examples/widgets/textbox.py index 1f233fbd6594..f93b72f134e3 100644 --- a/examples/widgets/textbox.py +++ b/examples/widgets/textbox.py @@ -3,15 +3,14 @@ Textbox ======= -Allowing text input with the Textbox widget. - -You can use the Textbox widget to let users interactively provide any text -that needs to be displayed, including formulas. You can use a submit button to -create plots with the given input. - -Note to not get confused with -:doc:`/tutorials/text/annotations` and -:doc:`/gallery/recipes/placing_text_boxes`, both of which are static elements. +The Textbox widget lets users interactively provide text input, including +formulas. In this example, the plot is updated using the `.on_submit` method. +This method triggers the execution of the `submit` function when the user +presses enter in the textbox or leaves the textbox. + +Note: The `Textbox` widget is different from the following static elements: +:doc:`/tutorials/text/annotations` and +:doc:`/gallery/recipes/placing_text_boxes`. """ import numpy as np @@ -22,13 +21,17 @@ t = np.arange(-2.0, 2.0, 0.001) s = t ** 2 initial_text = "t ** 2" -l, = plt.plot(t, s, lw=2) +l, = plt.plot(t, s, lw=2) # make a plot for the math expression "t ** 2" + +def submit(expression): + """ + Update the plotted function to the new math *expression*. -def submit(text): - # user can enter a new math expression that uses "t" as its independent - # variable. The plot refreshes on entering. Example: try "t ** 3" - ydata = eval(text) + *expession* is a string using "t" as its independent variable, e.g. + "t ** 3". + """ + ydata = eval(expression) l.set_ydata(ydata) ax.set_ylim(np.min(ydata), np.max(ydata)) plt.draw() From 4f6b9f3fd8fe2ec08f4d9face86f6069c6a8ca95 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 19 Feb 2020 18:22:36 -0800 Subject: [PATCH 3/3] minor fix to address CI failures --- examples/widgets/textbox.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/widgets/textbox.py b/examples/widgets/textbox.py index f93b72f134e3..96d1133686d9 100644 --- a/examples/widgets/textbox.py +++ b/examples/widgets/textbox.py @@ -5,11 +5,11 @@ The Textbox widget lets users interactively provide text input, including formulas. In this example, the plot is updated using the `.on_submit` method. -This method triggers the execution of the `submit` function when the user -presses enter in the textbox or leaves the textbox. +This method triggers the execution of the *submit* function when the +user presses enter in the textbox or leaves the textbox. -Note: The `Textbox` widget is different from the following static elements: -:doc:`/tutorials/text/annotations` and +Note: The `matplotlib.widgets.TextBox` widget is different from the following +static elements: :doc:`/tutorials/text/annotations` and :doc:`/gallery/recipes/placing_text_boxes`. """