Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
Exporting concise SVG#30598
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Exporting concise SVG#30598
Uh oh!
There was an error while loading.Please reload this page.
Conversation
draw_path_instead=False | ||
# Below two lines are only for testing/comparing | ||
# and can be removed | ||
withopen('pure_svg_mode','r')asf: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
If we were to merge this, we would have to provide an rcparam to control it (like we do with text in vector backends that let you pick "text + embed the fonts / hope they are available in the viewer" vs "draw text as paths")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
with open('pure_svg_mode', 'r') as f:
isNOT for merging (release version). It's simply there to perform my comparison tests as mentioned in my Test Code Repository (link in issue description), i.e., to compare between the old method and the new method. It will be deleted.
common_args= (gc, | ||
base_transform, | ||
draw_path_args[2])# rgbFace | ||
ifisinstance(patch, (Polygon,RegularPolygon, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I believe that we now have a high enough minimum python we can use thematch
statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Oh yes, I will make that change.
I was also wondering if instead of multiple conditions in this draw function, shouldn't they be called from within their respective classes itself? Or is this the right way forward?
withopen('pure_svg_mode','r')asf: | ||
iff.read()=='1': | ||
frommatplotlib.backends.backend_mixedimportMixedModeRenderer | ||
ifisinstance(renderer,MixedModeRenderer)andrenderer.is_svg_renderer(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Rather than pin to the svg renderer, if we are going to do this then we should duck-type and allow backends to opt-in to providing more specialized rendering calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I agree, something to work on.
I'm mildly in favor of this conceptually, but I think the first thing to sort out is how we want to allow backends to provide additional methods that not all have. I think the path is to add "additional methods that backendsmay implement for specialization reasons" + an rcparam to globally turn trying to use them on/off. This is not perfectly clear (as say the users asks for specialization and the backend happens to have Unfortunately given that we require changes inside of |
melwyncarlo commentedSep 25, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I agree this will take time and a lot of revisions. I thought there was only one SVG backend. Are there others? I'm not well knowledgeable on the topic ofspecialisation that you're talking about. Extension modules for SVG implementation or backends? Wouldn't markers too internally be simplified into their basic shape classes? |
anntzer commentedSep 29, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The cairo (internal) and mplcairo (third-party) backends can also render to svg. |
I'd like to bring backend versioning back to the table.#30559 While it doesn't solve all issues here, it would really help to formally specify variants of the backend API. |
I don't think we should really ever require (or suggest that it be required) that backends provide all these draw_foo methods. Something more reasonable may be to add a single pair of |
Similar happens for text; you can implement |
Uh oh!
There was an error while loading.Please reload this page.
PR summary
Currently all SVG elements are exported as path, which is currently the most viable solution, as other solutions have their pitfalls. But a concise and apt SVG could make things better and is something probably to work on.
This PRcloses#17424. (well, not really, just wanted to link it to the issue as per the PR checklist)
It's not the final solution but it solves the problem. There are restrictions involved in this solution (reference):
I have performed relevant tests:
P.S.: It's not meant to pass any CI/CD tests, as the solution itself is assumed to be subject to changes.