René's URL Explorer Experiment


Title: Rasterization creates multiple bitmap elements and large file sizes · Issue #17149 · matplotlib/matplotlib · GitHub

Open Graph Title: Rasterization creates multiple bitmap elements and large file sizes · Issue #17149 · matplotlib/matplotlib

X Title: Rasterization creates multiple bitmap elements and large file sizes · Issue #17149 · matplotlib/matplotlib

Description: Bug summary I often work with plots have have a large number of lines, for example showing the trajectories of a large number of particles in a physics simulation. For publication it is good for the axis to be in vector format, but keepi...

Open Graph Description: Bug summary I often work with plots have have a large number of lines, for example showing the trajectories of a large number of particles in a physics simulation. For publication it is good for th...

X Description: Bug summary I often work with plots have have a large number of lines, for example showing the trajectories of a large number of particles in a physics simulation. For publication it is good for th...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Rasterization creates multiple bitmap elements and large file sizes","articleBody":"**Bug summary**\r\n\r\nI often work with plots have have a large number of lines, for example showing the trajectories of a large number of particles in a physics simulation. For publication it is good for the axis to be in vector format, but keeping all the tracks as vector can create large file sizes.\r\n\r\nRasterization of some elements in the plot can solve this. Matplotlib offers `rasterized` kwarg to `plot()`, or `Artist.set_rasterized()`. But for this use case it results in a separate bitmap element for each line, making the file size even larger.\r\n\r\nI'm not the first person to have issues related to this #13718\r\n\r\n**Code for reproduction**\r\n\r\nFor example, this creates a 2.6MB file:\r\n\r\n```\r\nN = 20\r\nrast = True\r\n\r\ns = np.arange(100)\r\ntracks = []\r\n\r\nfor a in np.logspace(0.001, 0.5, N):\r\n\tfor t in np.linspace(0.1, pi, N):\r\n\t\tt = a*np.sin(s*0.05 + t)\r\n\t\ttracks.append(t)\r\n\r\nfor t in tracks:\r\n\tplt.plot(s, t, \"-k\", alpha=0.5, lw=0.5, rasterized=rast)\r\nplt.savefig(\"tracks1.svg\")\r\n```\r\n`grep \"\u003cimage\" tracks1.svg | wc -l` shows that there are 400 image elements.\r\n\r\nCalling plot just once with all the tracks makes no difference.\r\n\r\n```\r\ntracks_na = np.array(tracks).T\r\nplt.plot(s, tracks_na, \"-k\", alpha=0.5, lw=0.5, rasterized=rast)\r\n```\r\n\r\n\r\n**RFC**\r\n\r\nThis happens due to the way `start_rasterizing()` and `stop_rasterizing()` get called the from `allow_rasterization()` wrapper. If `rasterized` is set on the Line2D objects, then start and stop are called around each Line2D.draw(). `stop_rasterizing()` renders out to bitmap and calls `_renderer.draw_image()`. The only way to stay in rasterizing mode is `set_rasterized()` on the parent artist of the lines, which would be the axes, but that means that the axes labels and everything else get rasterized.\r\n\r\nI have thought of a few solutions, but I would like some feedback before starting.\r\n\r\nI think an ideal solution would be automatic for the user. matplotlib would just merge the bitmaps in an optimal way. This would need not effect draw order, so would need to be smart about zorder. It might avoid merging 2 non-overlapping bitmaps if that increases total area of bitmap.\r\n\r\nA possible implementation would be changes to the `allow_rasterization` wrapper so that the rasterization does not stop between consecutive rasterized artists.\r\n\r\nA more manual approach is to create an object that can contain multiple artists, and therefor keep the render in rasterization mode for drawing those artists. `Collections` don't fit this role as they have some limitations, e.g. `LineCollection` does not have markers. I also looked at `Container` but that seems designed for specific use cases. So this could be `ArtistGroup` or `ArtistCollection`. It would derive from Artist, and its `draw()` method would iterate through its children and draw them.\r\n\r\nI have a minimal prototype, that lets me do:\r\n```\r\nag = ArtistGroup()\r\nfor t in tracks:\r\n\tag.add_child(matplotlib.lines.Line2D(s, t, color=\"k\", linestyle=\"-\", alpha=0.5, lw=0.5))\r\nag.set_rasterized(True)\r\nplt.gca().add_artist(ag)\r\nplt.savefig(\"tracks3.svg\")\r\n```\r\nThis results in a 304 kB file with a single `\u003cimage\u003e` element (compared with 2.6 MB with original code). Increasing `N` makes the file size difference even larger.\r\n\r\nIf this is a good approach it could maybe be used inside the `plot()` and similar commands, so that lines drawn with a single plot would end up in a single rasterization (when requested) with no further user input.\r\n\r\n**Matplotlib version**\r\n\r\n  * Operating system: Linux\r\n  * Matplotlib version: 3.0.3 and git master\r\n  * Matplotlib backend: svg\r\n  * Python version: 3.7.6\r\n\r\nNote, I have been testing with the SVG backend, because its easier to see what is going on the output files. Judging from file size and loading times all this is true in the PDF backend too.","author":{"url":"https://github.com/samtygier","@type":"Person","name":"samtygier"},"datePublished":"2020-04-15T10:50:22.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/17149/matplotlib/issues/17149"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:d70e922b-be1e-bb90-8da5-f81d9d1e1d00
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCE76:1D4F69:54D81D:70B0E0:6A52F9D0
html-safe-nonce0116e2a6285d1479c5a87dedaa7c83cf7c3bf3f52de3bbec9c3ac503a833b9aa
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRTc2OjFENEY2OTo1NEQ4MUQ6NzBCMEUwOjZBNTJGOUQwIiwidmlzaXRvcl9pZCI6IjE5NTMwODA1NDkzNTk5NDIwOTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac5c0c141aecb1a66fff1904d1a461ef16d862591c639122fc6f63b4c630019825
hovercard-subject-tagissue:600205697
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/17149/issue_layout
twitter:imagehttps://opengraph.githubassets.com/2e7d9933f665235a70770ec38c60c362023ffe2a7b52dacd6b5febbdc0797508/matplotlib/matplotlib/issues/17149
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/2e7d9933f665235a70770ec38c60c362023ffe2a7b52dacd6b5febbdc0797508/matplotlib/matplotlib/issues/17149
og:image:altBug summary I often work with plots have have a large number of lines, for example showing the trajectories of a large number of particles in a physics simulation. For publication it is good for th...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamesamtygier
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
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
release07a982c1d40157c619b364352b704c3ce66bb332
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/matplotlib/matplotlib/issues/17149#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F17149
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%2F17149
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/17149
Reloadhttps://github.com/matplotlib/matplotlib/issues/17149
Reloadhttps://github.com/matplotlib/matplotlib/issues/17149
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/17149
matplotlib https://github.com/matplotlib
matplotlibhttps://github.com/matplotlib/matplotlib
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/17149
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 408 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
#17160https://github.com/matplotlib/matplotlib/pull/17160
#17159https://github.com/matplotlib/matplotlib/pull/17159
Rasterization creates multiple bitmap elements and large file sizeshttps://github.com/matplotlib/matplotlib/issues/17149#top
#17160https://github.com/matplotlib/matplotlib/pull/17160
#17159https://github.com/matplotlib/matplotlib/pull/17159
New featurehttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22New%20feature%22
v3.4.0https://github.com/matplotlib/matplotlib/milestone/53
https://github.com/samtygier
samtygierhttps://github.com/samtygier
on Apr 15, 2020https://github.com/matplotlib/matplotlib/issues/17149#issue-600205697
#13718https://github.com/matplotlib/matplotlib/issues/13718
New featurehttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22New%20feature%22
v3.4.0https://github.com/matplotlib/matplotlib/milestone/53
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.