8000 Fix single-shot timers in nbagg backend by joferkington · Pull Request #4892 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fix single-shot timers in nbagg backend #4892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 12, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added user-acceptance-tests for nbagg timers
  • Loading branch information
joferkington committed Aug 10, 2015
commit e68c62b2940c576ec5fbe4c04c4c4d518a3aea7a
178 changes: 157 additions & 21 deletions lib/matplotlib/backends/web_backend/nbagg_uat.ipynb
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
{
"metadata": {
"name": "",
"signature": "sha256:a1ac68aba163c75eab3d1fc91aa4d9a8ca66b09159619563827a19967d96814b"
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
},
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
Expand All @@ -17,7 +33,8 @@
],
"language": "python",
"metadata": {},
"outputs": []
"outputs": [],
"prompt_number": null
},
{
"cell_type": "markdown",
Expand All @@ -42,7 +59,8 @@
],
"language": "python",
"metadata": {},
"outputs": []
"outputs": [],
"prompt_number": null
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -70,7 +88,8 @@
],
"language": "python",
"metadata": {},
"outputs": []
"outputs": [],
"prompt_number": null
},
{
"cell_type": "markdown",
Expand All @@ -90,7 +109,8 @@
],
"language": "python",
"metadata": {},
"outputs": []
"outputs": [],
"prompt_number": null
},
{
"cell_type": "markdown",
Expand All @@ -109,7 +129,8 @@
],
"language": "python",
"metadata": {},
"outputs": []
"outputs": [],
"prompt_number": null
},
{
"cell_type": "markdown",
Expand All @@ -128,7 +149,8 @@
],
"language": "python",
"metadata": {},
"outputs": []
"outputs": [],
"prompt_number": null
},
{
"cell_type": "markdown",
Expand All @@ -148,7 +170,8 @@
],
"language": "python",
"metadata": {},
"outputs": []
"outputs": [],
"prompt_number": null
},
{
"cell_type": "markdown",
Expand All @@ -167,7 +190,8 @@
],
"language": "python",
"metadata": {},
"outputs": []
"outputs": [],
"prompt_number": null
},
{
"cell_type": "markdown",
Expand All @@ -189,7 +213,8 @@
],
"language": "python",
"metadata": {},
"outputs": []
"outputs": [],
"prompt_number": null
},
{
"cell_type": "markdown",
Expand All @@ -210,7 +235,8 @@
],
"language": "python",
"metadata": {},
"outputs": []
"outputs": [],
"prompt_number": null
},
{
"cell_type": "markdown",
Expand All @@ -227,7 +253,8 @@
],
"language": "python",
"metadata": {},
"outputs": []
"outputs": [],
"prompt_number": null
},
{
"cell_type": "markdown",
Expand All @@ -244,7 +271,8 @@
],
"language": "python",
"metadata": {},
"outputs": []
"outputs": [],
"prompt_number": null
},
{
"cell_type": "markdown",
Expand All @@ -263,7 +291,8 @@
],
"language": "python",
"metadata": {},
"outputs": []
"outputs": [],
"prompt_number": null
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -298,7 +327,8 @@
],
"language": "python",
"metadata": {},
"outputs": []
"outputs": [],
"prompt_number": null
},
{
"cell_type": "markdown",
Expand All @@ -323,7 +353,8 @@
],
"language": "python",
"metadata": {},
"outputs": []
"outputs": [],
"prompt_number": null
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -361,7 +392,8 @@
],
"language": "python",
"metadata": {},
"outputs": []
"outputs": [],
"prompt_number": null
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -394,7 +426,8 @@
],
"language": "python",
"metadata": {},
"outputs": []
"outputs": [],
"prompt_number": null
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -438,10 +471,113 @@
],
"language": "python",
"metadata": {},
"outputs": []
"outputs": [],
"prompt_number": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### UAT 17 - Timers\n",
"\n",
"Single-shot timers follow a completely different code path in the nbagg backend than regular timers (such as those used in the animation example above.) The next set of tests ensures that both \"regular\" and \"single-shot\" timers work properly.\n",
"\n",
"The following should show a simple clock that updates twice a second:"
]
},
{
"cell_type": "code",
"collapsed": true,
"input": [
"import time\n",
"\n",
"fig, ax = plt.subplots()\n",
"text = ax.text(0.5, 0.5, '', ha='center')\n",
"\n",
"def update(text):\n",
" text.set(text=time.ctime())\n",
" text.axes.figure.canvas.draw()\n",
" \n",
"timer = fig.canvas.new_timer(500, [(update, [text], {})])\n",
"timer.start()\n",
"plt.show()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"However, the following should only update once and then stop:"
]
},
{
"cell_type": "code",
"collapsed": true,
"input": [
"fig, ax = plt.subplots()\n",
"text = ax.text(0.5, 0.5, '', ha='center') \n",
"timer = fig.canvas.new_timer(500, [(update, [text], {})])\n",
"\n",
"time.single_shot = True\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be timer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops! I'd fixed that in the notebook I was running but forgot to save it before committing. Thanks for catching that!

"timer.start()\n",
"\n",
"plt.show()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And the next two examples should never show any visible text at all:"
]
},
{
"cell_type": "code",
"collapsed": true,
"input": [
"fig, ax = plt.subplots()\n",
"text = ax.text(0.5, 0.5, '', ha='center')\n",
"timer = fig.canvas.new_timer(500, [(update, [text], {})])\n",
"\n",
"timer.start()\n",
"timer.stop()\n",
"\n",
"plt.show()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": null
},
{
"cell_type": "code",
"collapsed": true,
"input": [
"fig, ax = plt.subplots()\n",
"text = ax.text(0.5, 0.5, '', ha='center')\n",
"timer = fig.canvas.new_timer(500, [(update, [text], {})])\n",
"\n",
"timer.single_shot = True\n",
"timer.start()\n",
"timer.stop()\n",
"\n",
"plt.show()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": null
}
],
"metadata": {}
}
]
}
}
0