René's URL Explorer Experiment


Title: [BUG]: frame paths relative to the html file when saving an animation to html · Issue #23581 · matplotlib/matplotlib · GitHub

Open Graph Title: [BUG]: frame paths relative to the html file when saving an animation to html · Issue #23581 · matplotlib/matplotlib

X Title: [BUG]: frame paths relative to the html file when saving an animation to html · Issue #23581 · matplotlib/matplotlib

Description: Problem Let's take the example from https://matplotlib.org/stable/gallery/animation/animate_decay.html import itertools import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation def data_gen(): for cnt i...

Open Graph Description: Problem Let's take the example from https://matplotlib.org/stable/gallery/animation/animate_decay.html import itertools import numpy as np import matplotlib.pyplot as plt import matplotlib.animatio...

X Description: Problem Let's take the example from https://matplotlib.org/stable/gallery/animation/animate_decay.html import itertools import numpy as np import matplotlib.pyplot as plt import matplotlib.anim...

Opengraph URL: https://github.com/matplotlib/matplotlib/issues/23581

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[BUG]: frame paths relative to the html file when saving an animation to html","articleBody":"### Problem\n\nLet's take the example from https://matplotlib.org/stable/gallery/animation/animate_decay.html\r\n\r\n```python\r\n\r\nimport itertools\r\n\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\nimport matplotlib.animation as animation\r\n\r\n\r\ndef data_gen():\r\n    for cnt in itertools.count():\r\n        t = cnt / 10\r\n        yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)\r\n\r\n\r\ndef init():\r\n    ax.set_ylim(-1.1, 1.1)\r\n    ax.set_xlim(0, 10)\r\n    del xdata[:]\r\n    del ydata[:]\r\n    line.set_data(xdata, ydata)\r\n    return line,\r\n\r\nfig, ax = plt.subplots()\r\nline, = ax.plot([], [], lw=2)\r\nax.grid()\r\nxdata, ydata = [], []\r\n\r\n\r\ndef run(data):\r\n    # update the data\r\n    t, y = data\r\n    xdata.append(t)\r\n    ydata.append(y)\r\n    xmin, xmax = ax.get_xlim()\r\n\r\n    if t \u003e= xmax:\r\n        ax.set_xlim(xmin, 2*xmax)\r\n        ax.figure.canvas.draw()\r\n    line.set_data(xdata, ydata)\r\n\r\n    return line,\r\n\r\nani = animation.FuncAnimation(fig, run, data_gen, interval=10, init_func=init)\r\nplt.show()\r\n```\r\n\r\nIt works great and I can easily save the animation to html using code such as:\r\n\r\n```python\r\nfrom matplotlib.animation import HTMLWriter\r\n\r\nfname = \"path/to/myfile.html\"\r\nwriter = HTMLWriter(fps=5)\r\nwriter.frame_format = \"svg\" # Ensure svg format\r\nani.save(fname, writer=writer)\r\n```\r\n\r\nI can open the html animation from a browser or display it in a jupyter notebook:\r\n\r\n```python\r\nfrom IPython.display import HTML\r\n\r\n# Display the animation\r\nHTML(fname_html.read_text())\r\n```\r\n\r\nThe problem is that within the html file, the path to the frames is hardcoded rather than being relative to the \r\nhtml file. So if you change the location of the html file, it does not work anymore.\r\n\r\n```js\r\n\r\n\u003cscript language=\"javascript\"\u003e\r\n  /* Instantiate the Animation class. */\r\n  /* The IDs given should match those used in the template above. */\r\n  (function() {\r\n    var img_id = \"_anim_imga5cbaf4d0c4c4ffda374436a276eff4b\";\r\n    var slider_id = \"_anim_slidera5cbaf4d0c4c4ffda374436a276eff4b\";\r\n    var loop_select_id = \"_anim_loop_selecta5cbaf4d0c4c4ffda374436a276eff4b\";\r\n    var frames = new Array(100);\r\n   \r\n  for (var i=0; i\u003c100; i++){\r\n    frames[i] = \"path/to/myfile_frames/frame\" + (\"0000000\" + i).slice(-7) +\r\n                \".svg\";\r\n  }\r\n\r\n\r\n    /* set a timeout to make sure all the above elements are created before\r\n       the object is initialized. */\r\n    setTimeout(function() {\r\n        anima5cbaf4d0c4c4ffda374436a276eff4b = new Animation(frames, img_id, slider_id, 200,\r\n                                 loop_select_id);\r\n    }, 0);\r\n  })()\r\n\u003c/script\u003e\r\n\r\n```\r\n\r\nYou can feed `ani.save(fname, writer=writer)` with a relative `fname` but in that case, it works in jupyter only if the html file is in the same folder than the notebook.\n\n### Proposed solution\n\nThe best would be to modify the javascript so it can get the path of the html file on the fly. I tried:\r\n\r\n```js\r\n\r\n\u003cscript language=\"javascript\"\u003e\r\n  /* Instantiate the Animation class. */\r\n  /* The IDs given should match those used in the template above. */\r\n  (function() {\r\n    var img_id = \"_anim_imga5cbaf4d0c4c4ffda374436a276eff4b\";\r\n    var slider_id = \"_anim_slidera5cbaf4d0c4c4ffda374436a276eff4b\";\r\n    var loop_select_id = \"_anim_loop_selecta5cbaf4d0c4c4ffda374436a276eff4b\";\r\n    var frames = new Array(100);\r\n    var scripts = document.getElementsByTagName(\"script\"), src = scripts[scripts.length-1].src;\r\n\r\n   \r\n  for (var i=0; i\u003c100; i++){\r\n    frames[i] = src + \"myfile_frames/frame\" + (\"0000000\" + i).slice(-7) +\r\n                \".svg\";\r\n  }\r\n\r\n\r\n    /* set a timeout to make sure all the above elements are created before\r\n       the object is initialized. */\r\n    setTimeout(function() {\r\n        anima5cbaf4d0c4c4ffda374436a276eff4b = new Animation(frames, img_id, slider_id, 200,\r\n                                 loop_select_id);\r\n    }, 0);\r\n  })()\r\n\u003c/script\u003e\r\n\r\n```\r\n\r\nAnd it works at least in Firefox and Chrome. However, it does not work for:\r\n\r\n```python\r\nfrom IPython.display import HTML\r\n\r\n# Display the animation\r\nHTML(fname_html.read_text())\r\n```","author":{"url":"https://github.com/antoinecollet5","@type":"Person","name":"antoinecollet5"},"datePublished":"2022-08-08T10:13:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/23581/matplotlib/issues/23581"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:1b82e313-f12b-8d6c-c9e3-01e7a7f1e19b
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9414:2E11B4:2D608D6:4077252:6A512356
html-safe-nonce6e48569507dfe365212793df9596ab95f9fb3fc077dbd6405f785f81b2ad5151
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NDE0OjJFMTFCNDoyRDYwOEQ2OjQwNzcyNTI6NkE1MTIzNTYiLCJ2aXNpdG9yX2lkIjoiNDk3NDUzNTU2OTAyNTYwNjQ4NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac8500be47d4c619795a998084d1f9f3276e4fbef72220fb2bece4b3b1dd336d54
hovercard-subject-tagissue:1331643705
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/23581/issue_layout
twitter:imagehttps://opengraph.githubassets.com/95f66411a9c5caa573909a2ca319afb09ceed74b22edf72797e7d8c8b387af30/matplotlib/matplotlib/issues/23581
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/95f66411a9c5caa573909a2ca319afb09ceed74b22edf72797e7d8c8b387af30/matplotlib/matplotlib/issues/23581
og:image:altProblem Let's take the example from https://matplotlib.org/stable/gallery/animation/animate_decay.html import itertools import numpy as np import matplotlib.pyplot as plt import matplotlib.animatio...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameantoinecollet5
hostnamegithub.com
expected-hostnamegithub.com
None689b683944b0d7f015d0e776452c970832fa81b82dc15284469b556ecced715b
turbo-cache-controlno-preview
go-importgithub.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git
octolytics-dimension-user_id215947
octolytics-dimension-user_loginmatplotlib
octolytics-dimension-repository_id1385122
octolytics-dimension-repository_nwomatplotlib/matplotlib
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1385122
octolytics-dimension-repository_network_root_nwomatplotlib/matplotlib
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release942b51ed3bd5feee3d5e2719f890a5fe286edbbb
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/matplotlib/matplotlib/issues/23581#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F23581
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F23581
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=matplotlib%2Fmatplotlib
Reloadhttps://github.com/matplotlib/matplotlib/issues/23581
Reloadhttps://github.com/matplotlib/matplotlib/issues/23581
Reloadhttps://github.com/matplotlib/matplotlib/issues/23581
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/23581
matplotlib https://github.com/matplotlib
matplotlibhttps://github.com/matplotlib/matplotlib
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/23581
Notifications https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Fork 8.4k https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Star 23k https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Code https://github.com/matplotlib/matplotlib
Issues 1.1k https://github.com/matplotlib/matplotlib/issues
Pull requests 409 https://github.com/matplotlib/matplotlib/pulls
Actions https://github.com/matplotlib/matplotlib/actions
Projects https://github.com/matplotlib/matplotlib/projects
Wiki https://github.com/matplotlib/matplotlib/wiki
Security and quality 0 https://github.com/matplotlib/matplotlib/security
Insights https://github.com/matplotlib/matplotlib/pulse
Code https://github.com/matplotlib/matplotlib
Issues https://github.com/matplotlib/matplotlib/issues
Pull requests https://github.com/matplotlib/matplotlib/pulls
Actions https://github.com/matplotlib/matplotlib/actions
Projects https://github.com/matplotlib/matplotlib/projects
Wiki https://github.com/matplotlib/matplotlib/wiki
Security and quality https://github.com/matplotlib/matplotlib/security
Insights https://github.com/matplotlib/matplotlib/pulse
#24482https://github.com/matplotlib/matplotlib/pull/24482
[BUG]: frame paths relative to the html file when saving an animation to htmlhttps://github.com/matplotlib/matplotlib/issues/23581#top
#24482https://github.com/matplotlib/matplotlib/pull/24482
topic: animationhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22topic%3A%20animation%22
v3.6.3https://github.com/matplotlib/matplotlib/milestone/76
https://github.com/antoinecollet5
antoinecollet5https://github.com/antoinecollet5
on Aug 8, 2022https://github.com/matplotlib/matplotlib/issues/23581#issue-1331643705
https://matplotlib.org/stable/gallery/animation/animate_decay.htmlhttps://matplotlib.org/stable/gallery/animation/animate_decay.html
topic: animationhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22topic%3A%20animation%22
v3.6.3https://github.com/matplotlib/matplotlib/milestone/76
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.