Title: [MNT]: TimedAnimation event loop interval · Issue #28647 · matplotlib/matplotlib · GitHub
Open Graph Title: [MNT]: TimedAnimation event loop interval · Issue #28647 · matplotlib/matplotlib
X Title: [MNT]: TimedAnimation event loop interval · Issue #28647 · matplotlib/matplotlib
Description: Summary TimedAnimation resets the event timer at the end of its _step() method: matplotlib/lib/matplotlib/animation.py Line 1446 in f7b3def self.event_source.interval = self._interval As far as I can tell, this is by design. The original...
Open Graph Description: Summary TimedAnimation resets the event timer at the end of its _step() method: matplotlib/lib/matplotlib/animation.py Line 1446 in f7b3def self.event_source.interval = self._interval As far as I c...
X Description: Summary TimedAnimation resets the event timer at the end of its _step() method: matplotlib/lib/matplotlib/animation.py Line 1446 in f7b3def self.event_source.interval = self._interval As far as I c...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/28647
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[MNT]: TimedAnimation event loop interval","articleBody":"### Summary\n\n`TimedAnimation` resets the event timer at the end of its `_step()` method: \r\n\r\nhttps://github.com/matplotlib/matplotlib/blob/f7b3def52b39a070064e0e713042cd948c985643/lib/matplotlib/animation.py#L1446\r\n\r\nAs far as I can tell, this is by design. The original commit included this comment:\r\n\r\nhttps://github.com/matplotlib/matplotlib/blob/70e401fe681b6e32ed5fdbf7eea182828887d75b/lib/matplotlib/animation.py#L314-L318\r\n\r\nTo me, this was suprising and it took me a while to get to the bottom of it. From the documentation I took that the event loop calls the animation target at exactly the `interval` specified. However, the current implementation means that it actually calls it at `interval + time_in_callback`. In case the callback does some heavy lifting, like processing data or communicating with an instrument, this can add significant overhead to the real interval between frames.\r\n\r\n\u003cdetails\u003e\r\n\u003csummary\u003e\r\nA MWE highlighting the effects of resetting the interval:\r\n\u003c/summary\u003e\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\nfrom matplotlib import animation\r\n\r\ndef update(frame):\r\n if len(frame) \u003c 2:\r\n return []\r\n diff = np.diff(frame)\r\n avg.set_text(avg_txt.format(diff.mean()*1e3))\r\n cur.set_text(cur_txt.format(diff[-1]*1e3))\r\n return [avg, cur]\r\n\r\n\r\ndef frame():\r\n times = deque(maxlen=100)\r\n while True:\r\n time.sleep(0.1)\r\n times.append(time.perf_counter())\r\n yield times\r\n \r\nfig, ax = plt.subplots(figsize=(1,1))\r\nax.axis('off')\r\navg_txt = 'avg: {:.3g} ms'\r\ncur_txt = 'cur: {:.3g} ms'\r\navg = ax.text(0.5, 0.75, avg_txt.format(0), va='center', ha='center')\r\ncur = ax.text(0.5, 0.25, cur_txt.format(0), va='center', ha='center')\r\n\r\nanim = animation.FuncAnimation(fig, update, frame, repeat=False,\r\n cache_frame_data=False, interval=200)\r\n```\r\n\r\n\u003c/details\u003e\r\n\r\nWith the current behavior, this results in an effective interval of 300 ms. Commenting out [the line resetting the interval](https://github.com/matplotlib/matplotlib/blob/f7b3def52b39a070064e0e713042cd948c985643/lib/matplotlib/animation.py#L1446) results in the effective interval I would expect from `interval=200`, 200 ms.\n\n### Proposed fix\n\nThere might be reasonable usecases for resetting the interval, but I cannot see any right now. Hence, I would propose to leave the timer running uninterrupted, i.e., dropping\r\n\r\nhttps://github.com/matplotlib/matplotlib/blob/f7b3def52b39a070064e0e713042cd948c985643/lib/matplotlib/animation.py#L1446\r\n","author":{"url":"https://github.com/thangleiter","@type":"Person","name":"thangleiter"},"datePublished":"2024-08-02T09:13:46.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/28647/matplotlib/issues/28647"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a973082a-0508-c18b-7685-3e5cf45622a2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A336:146969:2D8043:3C7CA0:6A52CAB2 |
| html-safe-nonce | a236fac3b1232f915b674d07a82c5ed69aff65de18864e555583f90f7960dc92 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzM2OjE0Njk2OToyRDgwNDM6M0M3Q0EwOjZBNTJDQUIyIiwidmlzaXRvcl9pZCI6IjIwNDQzNTEwNDM5NDEzNTQxNjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | fb3d4079f9b98184aba81ede9ba50607e6a19b89227e41738a708bcaf4dd5bef |
| hovercard-subject-tag | issue:2444488555 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/28647/issue_layout |
| twitter:image | https://opengraph.githubassets.com/de94ee557625fec86d849f3bbdf4e1e6e3d6bf539d4f4b9fd33038d21ff7f6ae/matplotlib/matplotlib/issues/28647 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/de94ee557625fec86d849f3bbdf4e1e6e3d6bf539d4f4b9fd33038d21ff7f6ae/matplotlib/matplotlib/issues/28647 |
| og:image:alt | Summary TimedAnimation resets the event timer at the end of its _step() method: matplotlib/lib/matplotlib/animation.py Line 1446 in f7b3def self.event_source.interval = self._interval As far as I c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | thangleiter |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width