Skip to content
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

[Bug]: Useless recursive group in SVG output when using path_effects #28146

Closed
szsdk opened this issue Apr 28, 2024 · 4 comments
Closed

[Bug]: Useless recursive group in SVG output when using path_effects #28146

szsdk opened this issue Apr 28, 2024 · 4 comments

Comments

@szsdk
Copy link

szsdk commented Apr 28, 2024

Bug summary

I noticed that when using path_effects in matplotlib, the SVG output contains a useless recursive group. This group is not present when path_effects is not used.

Code for reproduction

from io import StringIO

import matplotlib.patheffects as path_effects
import matplotlib.pylab as plt
from matplotlib.patches import Polygon

fig, ax = plt.subplots()
for _ in range(10):
    p = Polygon(
        [[0, 0], [1, 0], [1, 1], [0, 1]],
        edgecolor="0.00",
        # Try commenting out the next line to see the difference
        path_effects=[path_effects.Stroke(capstyle="round", joinstyle="round")],
    )
    ax.add_patch(p)

result = StringIO()
plt.savefig(result, format="svg")
print(result.getvalue())

Actual outcome

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns:xlink="http://www.w3.org/1999/xlink" width="460.8pt" height="345.6pt" viewBox="0 0 460.8 345.6" xmlns="http://www.w3.org/2000/svg" version="1.1">
 <metadata>
  <rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
   <cc:Work>
    <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
    <dc:date>2024-04-28T08:58:12.499321</dc:date>
    <dc:format>image/svg+xml</dc:format>
    <dc:creator>
     <cc:Agent>
      <dc:title>Matplotlib v3.8.3, https://matplotlib.org/</dc:title>
     </cc:Agent>
    </dc:creator>
   </cc:Work>
  </rdf:RDF>
 </metadata>
 <defs>
  <style type="text/css">*{stroke-linejoin: round; stroke-linecap: butt}</style>
 </defs>
 <g id="figure_1">
  <g id="patch_1">
   <path d="M 0 345.6 
L 460.8 345.6 
L 460.8 0 
L 0 0 
z
" style="fill: #ffffff"/>
  </g>
  <g id="axes_1">
   <g id="patch_2">
    <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" style="fill: #ffffff"/>
   </g>
   <g id="patch_3">
    <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" clip-path="url(#p6e5ca1158d)" style="fill: #1f77b4; stroke: #000000; stroke-linecap: round"/>
    <g id="patch_4">
     <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" clip-path="url(#p6e5ca1158d)" style="fill: #1f77b4; stroke: #000000; stroke-linecap: round"/>
     <g id="patch_5">
      <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" clip-path="url(#p6e5ca1158d)" style="fill: #1f77b4; stroke: #000000; stroke-linecap: round"/>
      <g id="patch_6">
       <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" clip-path="url(#p6e5ca1158d)" style="fill: #1f77b4; stroke: #000000; stroke-linecap: round"/>
       <g id="patch_7">
        <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" clip-path="url(#p6e5ca1158d)" style="fill: #1f77b4; stroke: #000000; stroke-linecap: round"/>
        <g id="patch_8">
         <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" clip-path="url(#p6e5ca1158d)" style="fill: #1f77b4; stroke: #000000; stroke-linecap: round"/>
         <g id="patch_9">
          <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" clip-path="url(#p6e5ca1158d)" style="fill: #1f77b4; stroke: #000000; stroke-linecap: round"/>
          <g id="patch_10">
           <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" clip-path="url(#p6e5ca1158d)" style="fill: #1f77b4; stroke: #000000; stroke-linecap: round"/>
           <g id="patch_11">
            <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" clip-path="url(#p6e5ca1158d)" style="fill: #1f77b4; stroke: #000000; stroke-linecap: round"/>
            <g id="patch_12">
             <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" clip-path="url(#p6e5ca1158d)" style="fill: #1f77b4; stroke: #000000; stroke-linecap: round"/>
             <g id="matplotlib.axis_1">
              <g id="xtick_1">
               <g id="line2d_1">
                <defs>
                 <path id="mdf68b02c80" d="M 0 0 
L 0 3.5 
" style="stroke: #000000; stroke-width: 0.8"/>
                </defs>
                <g>
                 <use xlink:href="#mdf68b02c80" x="57.6" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
                </g>
               </g>
               <g id="text_1">
                <!-- 0.0 -->
                <g transform="translate(49.648438 322.182437) scale(0.1 -0.1)">
                 <defs>
                  <path id="DejaVuSans-30" d="M 2034 4250 
Q 1547 4250 1301 3770 
Q 1056 3291 1056 2328 
Q 1056 1369 1301 889 
Q 1547 409 2034 409 
Q 2525 409 2770 889 
Q 3016 1369 3016 2328 
Q 3016 3291 2770 3770 
Q 2525 4250 2034 4250 
z
M 2034 4750 
Q 2819 4750 3233 4129 
Q 3647 3509 3647 2328 
Q 3647 1150 3233 529 
Q 2819 -91 2034 -91 
Q 1250 -91 836 529 
Q 422 1150 422 2328 
Q 422 3509 836 4129 
Q 1250 4750 2034 4750 
z
" transform="scale(0.015625)"/>
                  <path id="DejaVuSans-2e" d="M 684 794 
L 1344 794 
L 1344 0 
L 684 0 
L 684 794 
z
" transform="scale(0.015625)"/>
                 </defs>
                 <use xlink:href="#DejaVuSans-30"/>
                 <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
                 <use xlink:href="#DejaVuSans-30" x="95.410156"/>
                </g>
               </g>
              </g>
              <g id="xtick_2">
               <g id="line2d_2">
                <g>
                 <use xlink:href="#mdf68b02c80" x="129.024" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
                </g>
               </g>
               <g id="text_2">
                <!-- 0.2 -->
                <g transform="translate(121.072438 322.182437) scale(0.1 -0.1)">
                 <defs>
                  <path id="DejaVuSans-32" d="M 1228 531 
L 3431 531 
L 3431 0 
L 469 0 
L 469 531 
Q 828 903 1448 1529 
Q 2069 2156 2228 2338 
Q 2531 2678 2651 2914 
Q 2772 3150 2772 3378 
Q 2772 3750 2511 3984 
Q 2250 4219 1831 4219 
Q 1534 4219 1204 4116 
Q 875 4013 500 3803 
L 500 4441 
Q 881 4594 1212 4672 
Q 1544 4750 1819 4750 
Q 2544 4750 2975 4387 
Q 3406 4025 3406 3419 
Q 3406 3131 3298 2873 
Q 3191 2616 2906 2266 
Q 2828 2175 2409 1742 
Q 1991 1309 1228 531 
z
" transform="scale(0.015625)"/>
                 </defs>
                 <use xlink:href="#DejaVuSans-30"/>
                 <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
                 <use xlink:href="#DejaVuSans-32" x="95.410156"/>
                </g>
               </g>
              </g>
              <g id="xtick_3">
               <g id="line2d_3">
                <g>
                 <use xlink:href="#mdf68b02c80" x="200.448" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
                </g>
               </g>
               <g id="text_3">
                <!-- 0.4 -->
                <g transform="translate(192.496438 322.182437) scale(0.1 -0.1)">
                 <defs>
                  <path id="DejaVuSans-34" d="M 2419 4116 
L 825 1625 
L 2419 1625 
L 2419 4116 
z
M 2253 4666 
L 3047 4666 
L 3047 1625 
L 3713 1625 
L 3713 1100 
L 3047 1100 
L 3047 0 
L 2419 0 
L 2419 1100 
L 313 1100 
L 313 1709 
L 2253 4666 
z
" transform="scale(0.015625)"/>
                 </defs>
                 <use xlink:href="#DejaVuSans-30"/>
                 <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
                 <use xlink:href="#DejaVuSans-34" x="95.410156"/>
                </g>
               </g>
              </g>
              <g id="xtick_4">
               <g id="line2d_4">
                <g>
                 <use xlink:href="#mdf68b02c80" x="271.872" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
                </g>
               </g>
               <g id="text_4">
                <!-- 0.6 -->
                <g transform="translate(263.920438 322.182437) scale(0.1 -0.1)">
                 <defs>
                  <path id="DejaVuSans-36" d="M 2113 2584 
Q 1688 2584 1439 2293 
Q 1191 2003 1191 1497 
Q 1191 994 1439 701 
Q 1688 409 2113 409 
Q 2538 409 2786 701 
Q 3034 994 3034 1497 
Q 3034 2003 2786 2293 
Q 2538 2584 2113 2584 
z
M 3366 4563 
L 3366 3988 
Q 3128 4100 2886 4159 
Q 2644 4219 2406 4219 
Q 1781 4219 1451 3797 
Q 1122 3375 1075 2522 
Q 1259 2794 1537 2939 
Q 1816 3084 2150 3084 
Q 2853 3084 3261 2657 
Q 3669 2231 3669 1497 
Q 3669 778 3244 343 
Q 2819 -91 2113 -91 
Q 1303 -91 875 529 
Q 447 1150 447 2328 
Q 447 3434 972 4092 
Q 1497 4750 2381 4750 
Q 2619 4750 2861 4703 
Q 3103 4656 3366 4563 
z
" transform="scale(0.015625)"/>
                 </defs>
                 <use xlink:href="#DejaVuSans-30"/>
                 <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
                 <use xlink:href="#DejaVuSans-36" x="95.410156"/>
                </g>
               </g>
              </g>
              <g id="xtick_5">
               <g id="line2d_5">
                <g>
                 <use xlink:href="#mdf68b02c80" x="343.296" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
                </g>
               </g>
               <g id="text_5">
                <!-- 0.8 -->
                <g transform="translate(335.344438 322.182437) scale(0.1 -0.1)">
                 <defs>
                  <path id="DejaVuSans-38" d="M 2034 2216 
Q 1584 2216 1326 1975 
Q 1069 1734 1069 1313 
Q 1069 891 1326 650 
Q 1584 409 2034 409 
Q 2484 409 2743 651 
Q 3003 894 3003 1313 
Q 3003 1734 2745 1975 
Q 2488 2216 2034 2216 
z
M 1403 2484 
Q 997 2584 770 2862 
Q 544 3141 544 3541 
Q 544 4100 942 4425 
Q 1341 4750 2034 4750 
Q 2731 4750 3128 4425 
Q 3525 4100 3525 3541 
Q 3525 3141 3298 2862 
Q 3072 2584 2669 2484 
Q 3125 2378 3379 2068 
Q 3634 1759 3634 1313 
Q 3634 634 3220 271 
Q 2806 -91 2034 -91 
Q 1263 -91 848 271 
Q 434 634 434 1313 
Q 434 1759 690 2068 
Q 947 2378 1403 2484 
z
M 1172 3481 
Q 1172 3119 1398 2916 
Q 1625 2713 2034 2713 
Q 2441 2713 2670 2916 
Q 2900 3119 2900 3481 
Q 2900 3844 2670 4047 
Q 2441 4250 2034 4250 
Q 1625 4250 1398 4047 
Q 1172 3844 1172 3481 
z
" transform="scale(0.015625)"/>
                 </defs>
                 <use xlink:href="#DejaVuSans-30"/>
                 <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
                 <use xlink:href="#DejaVuSans-38" x="95.410156"/>
                </g>
               </g>
              </g>
              <g id="xtick_6">
               <g id="line2d_6">
                <g>
                 <use xlink:href="#mdf68b02c80" x="414.72" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
                </g>
               </g>
               <g id="text_6">
                <!-- 1.0 -->
                <g transform="translate(406.768438 322.182437) scale(0.1 -0.1)">
                 <defs>
                  <path id="DejaVuSans-31" d="M 794 531 
L 1825 531 
L 1825 4091 
L 703 3866 
L 703 4441 
L 1819 4666 
L 2450 4666 
L 2450 531 
L 3481 531 
L 3481 0 
L 794 0 
L 794 531 
z
" transform="scale(0.015625)"/>
                 </defs>
                 <use xlink:href="#DejaVuSans-31"/>
                 <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
                 <use xlink:href="#DejaVuSans-30" x="95.410156"/>
                </g>
               </g>
              </g>
             </g>
             <g id="matplotlib.axis_2">
              <g id="ytick_1">
               <g id="line2d_7">
                <defs>
                 <path id="m6cc60a5dec" d="M 0 0 
L -3.5 0 
" style="stroke: #000000; stroke-width: 0.8"/>
                </defs>
                <g>
                 <use xlink:href="#m6cc60a5dec" x="57.6" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
                </g>
               </g>
               <g id="text_7">
                <!-- 0.0 -->
                <g transform="translate(34.696875 311.383219) scale(0.1 -0.1)">
                 <use xlink:href="#DejaVuSans-30"/>
                 <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
                 <use xlink:href="#DejaVuSans-30" x="95.410156"/>
                </g>
               </g>
              </g>
              <g id="ytick_2">
               <g id="line2d_8">
                <g>
                 <use xlink:href="#m6cc60a5dec" x="57.6" y="254.3616" style="stroke: #000000; stroke-width: 0.8"/>
                </g>
               </g>
               <g id="text_8">
                <!-- 0.2 -->
                <g transform="translate(34.696875 258.160819) scale(0.1 -0.1)">
                 <use xlink:href="#DejaVuSans-30"/>
                 <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
                 <use xlink:href="#DejaVuSans-32" x="95.410156"/>
                </g>
               </g>
              </g>
              <g id="ytick_3">
               <g id="line2d_9">
                <g>
                 <use xlink:href="#m6cc60a5dec" x="57.6" y="201.1392" style="stroke: #000000; stroke-width: 0.8"/>
                </g>
               </g>
               <g id="text_9">
                <!-- 0.4 -->
                <g transform="translate(34.696875 204.938419) scale(0.1 -0.1)">
                 <use xlink:href="#DejaVuSans-30"/>
                 <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
                 <use xlink:href="#DejaVuSans-34" x="95.410156"/>
                </g>
               </g>
              </g>
              <g id="ytick_4">
               <g id="line2d_10">
                <g>
                 <use xlink:href="#m6cc60a5dec" x="57.6" y="147.9168" style="stroke: #000000; stroke-width: 0.8"/>
                </g>
               </g>
               <g id="text_10">
                <!-- 0.6 -->
                <g transform="translate(34.696875 151.716019) scale(0.1 -0.1)">
                 <use xlink:href="#DejaVuSans-30"/>
                 <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
                 <use xlink:href="#DejaVuSans-36" x="95.410156"/>
                </g>
               </g>
              </g>
              <g id="ytick_5">
               <g id="line2d_11">
                <g>
                 <use xlink:href="#m6cc60a5dec" x="57.6" y="94.6944" style="stroke: #000000; stroke-width: 0.8"/>
                </g>
               </g>
               <g id="text_11">
                <!-- 0.8 -->
                <g transform="translate(34.696875 98.493619) scale(0.1 -0.1)">
                 <use xlink:href="#DejaVuSans-30"/>
                 <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
                 <use xlink:href="#DejaVuSans-38" x="95.410156"/>
                </g>
               </g>
              </g>
              <g id="ytick_6">
               <g id="line2d_12">
                <g>
                 <use xlink:href="#m6cc60a5dec" x="57.6" y="41.472" style="stroke: #000000; stroke-width: 0.8"/>
                </g>
               </g>
               <g id="text_12">
                <!-- 1.0 -->
                <g transform="translate(34.696875 45.271219) scale(0.1 -0.1)">
                 <use xlink:href="#DejaVuSans-31"/>
                 <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
                 <use xlink:href="#DejaVuSans-30" x="95.410156"/>
                </g>
               </g>
              </g>
             </g>
             <g id="patch_13">
              <path d="M 57.6 307.584 
L 57.6 41.472 
" style="fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square"/>
             </g>
             <g id="patch_14">
              <path d="M 414.72 307.584 
L 414.72 41.472 
" style="fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square"/>
             </g>
             <g id="patch_15">
              <path d="M 57.6 307.584 
L 414.72 307.584 
" style="fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square"/>
             </g>
             <g id="patch_16">
              <path d="M 57.6 41.472 
L 414.72 41.472 
" style="fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square"/>
             </g>
            </g>
           </g>
           <defs>
            <clipPath id="p6e5ca1158d">
             <rect x="57.6" y="41.472" width="357.12" height="266.112"/>
            </clipPath>
           </defs>
          </g>
         </g>
        </g>
       </g>
      </g>
     </g>
    </g>
   </g>
  </g>
 </g>
</svg>

Expected outcome

I got this SVG output when commenting out the line path_effects=[path_effects.Stroke(capstyle="round", joinstyle="round")]:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns:xlink="http://www.w3.org/1999/xlink" width="460.8pt" height="345.6pt" viewBox="0 0 460.8 345.6" xmlns="http://www.w3.org/2000/svg" version="1.1">
 <metadata>
  <rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
   <cc:Work>
    <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
    <dc:date>2024-04-28T08:59:37.414050</dc:date>
    <dc:format>image/svg+xml</dc:format>
    <dc:creator>
     <cc:Agent>
      <dc:title>Matplotlib v3.8.3, https://matplotlib.org/</dc:title>
     </cc:Agent>
    </dc:creator>
   </cc:Work>
  </rdf:RDF>
 </metadata>
 <defs>
  <style type="text/css">*{stroke-linejoin: round; stroke-linecap: butt}</style>
 </defs>
 <g id="figure_1">
  <g id="patch_1">
   <path d="M 0 345.6 
L 460.8 345.6 
L 460.8 0 
L 0 0 
z
" style="fill: #ffffff"/>
  </g>
  <g id="axes_1">
   <g id="patch_2">
    <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" style="fill: #ffffff"/>
   </g>
   <g id="patch_3">
    <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" clip-path="url(#pa361fe6ebe)" style="fill: #1f77b4; stroke: #000000; stroke-linejoin: miter"/>
   </g>
   <g id="patch_4">
    <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" clip-path="url(#pa361fe6ebe)" style="fill: #1f77b4; stroke: #000000; stroke-linejoin: miter"/>
   </g>
   <g id="patch_5">
    <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" clip-path="url(#pa361fe6ebe)" style="fill: #1f77b4; stroke: #000000; stroke-linejoin: miter"/>
   </g>
   <g id="patch_6">
    <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" clip-path="url(#pa361fe6ebe)" style="fill: #1f77b4; stroke: #000000; stroke-linejoin: miter"/>
   </g>
   <g id="patch_7">
    <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" clip-path="url(#pa361fe6ebe)" style="fill: #1f77b4; stroke: #000000; stroke-linejoin: miter"/>
   </g>
   <g id="patch_8">
    <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" clip-path="url(#pa361fe6ebe)" style="fill: #1f77b4; stroke: #000000; stroke-linejoin: miter"/>
   </g>
   <g id="patch_9">
    <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" clip-path="url(#pa361fe6ebe)" style="fill: #1f77b4; stroke: #000000; stroke-linejoin: miter"/>
   </g>
   <g id="patch_10">
    <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" clip-path="url(#pa361fe6ebe)" style="fill: #1f77b4; stroke: #000000; stroke-linejoin: miter"/>
   </g>
   <g id="patch_11">
    <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" clip-path="url(#pa361fe6ebe)" style="fill: #1f77b4; stroke: #000000; stroke-linejoin: miter"/>
   </g>
   <g id="patch_12">
    <path d="M 57.6 307.584 
L 414.72 307.584 
L 414.72 41.472 
L 57.6 41.472 
z
" clip-path="url(#pa361fe6ebe)" style="fill: #1f77b4; stroke: #000000; stroke-linejoin: miter"/>
   </g>
   <g id="matplotlib.axis_1">
    <g id="xtick_1">
     <g id="line2d_1">
      <defs>
       <path id="m2c1c4f18cb" d="M 0 0 
L 0 3.5 
" style="stroke: #000000; stroke-width: 0.8"/>
      </defs>
      <g>
       <use xlink:href="#m2c1c4f18cb" x="57.6" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
      </g>
     </g>
     <g id="text_1">
      <!-- 0.0 -->
      <g transform="translate(49.648438 322.182437) scale(0.1 -0.1)">
       <defs>
        <path id="DejaVuSans-30" d="M 2034 4250 
Q 1547 4250 1301 3770 
Q 1056 3291 1056 2328 
Q 1056 1369 1301 889 
Q 1547 409 2034 409 
Q 2525 409 2770 889 
Q 3016 1369 3016 2328 
Q 3016 3291 2770 3770 
Q 2525 4250 2034 4250 
z
M 2034 4750 
Q 2819 4750 3233 4129 
Q 3647 3509 3647 2328 
Q 3647 1150 3233 529 
Q 2819 -91 2034 -91 
Q 1250 -91 836 529 
Q 422 1150 422 2328 
Q 422 3509 836 4129 
Q 1250 4750 2034 4750 
z
" transform="scale(0.015625)"/>
        <path id="DejaVuSans-2e" d="M 684 794 
L 1344 794 
L 1344 0 
L 684 0 
L 684 794 
z
" transform="scale(0.015625)"/>
       </defs>
       <use xlink:href="#DejaVuSans-30"/>
       <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
       <use xlink:href="#DejaVuSans-30" x="95.410156"/>
      </g>
     </g>
    </g>
    <g id="xtick_2">
     <g id="line2d_2">
      <g>
       <use xlink:href="#m2c1c4f18cb" x="129.024" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
      </g>
     </g>
     <g id="text_2">
      <!-- 0.2 -->
      <g transform="translate(121.072438 322.182437) scale(0.1 -0.1)">
       <defs>
        <path id="DejaVuSans-32" d="M 1228 531 
L 3431 531 
L 3431 0 
L 469 0 
L 469 531 
Q 828 903 1448 1529 
Q 2069 2156 2228 2338 
Q 2531 2678 2651 2914 
Q 2772 3150 2772 3378 
Q 2772 3750 2511 3984 
Q 2250 4219 1831 4219 
Q 1534 4219 1204 4116 
Q 875 4013 500 3803 
L 500 4441 
Q 881 4594 1212 4672 
Q 1544 4750 1819 4750 
Q 2544 4750 2975 4387 
Q 3406 4025 3406 3419 
Q 3406 3131 3298 2873 
Q 3191 2616 2906 2266 
Q 2828 2175 2409 1742 
Q 1991 1309 1228 531 
z
" transform="scale(0.015625)"/>
       </defs>
       <use xlink:href="#DejaVuSans-30"/>
       <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
       <use xlink:href="#DejaVuSans-32" x="95.410156"/>
      </g>
     </g>
    </g>
    <g id="xtick_3">
     <g id="line2d_3">
      <g>
       <use xlink:href="#m2c1c4f18cb" x="200.448" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
      </g>
     </g>
     <g id="text_3">
      <!-- 0.4 -->
      <g transform="translate(192.496438 322.182437) scale(0.1 -0.1)">
       <defs>
        <path id="DejaVuSans-34" d="M 2419 4116 
L 825 1625 
L 2419 1625 
L 2419 4116 
z
M 2253 4666 
L 3047 4666 
L 3047 1625 
L 3713 1625 
L 3713 1100 
L 3047 1100 
L 3047 0 
L 2419 0 
L 2419 1100 
L 313 1100 
L 313 1709 
L 2253 4666 
z
" transform="scale(0.015625)"/>
       </defs>
       <use xlink:href="#DejaVuSans-30"/>
       <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
       <use xlink:href="#DejaVuSans-34" x="95.410156"/>
      </g>
     </g>
    </g>
    <g id="xtick_4">
     <g id="line2d_4">
      <g>
       <use xlink:href="#m2c1c4f18cb" x="271.872" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
      </g>
     </g>
     <g id="text_4">
      <!-- 0.6 -->
      <g transform="translate(263.920438 322.182437) scale(0.1 -0.1)">
       <defs>
        <path id="DejaVuSans-36" d="M 2113 2584 
Q 1688 2584 1439 2293 
Q 1191 2003 1191 1497 
Q 1191 994 1439 701 
Q 1688 409 2113 409 
Q 2538 409 2786 701 
Q 3034 994 3034 1497 
Q 3034 2003 2786 2293 
Q 2538 2584 2113 2584 
z
M 3366 4563 
L 3366 3988 
Q 3128 4100 2886 4159 
Q 2644 4219 2406 4219 
Q 1781 4219 1451 3797 
Q 1122 3375 1075 2522 
Q 1259 2794 1537 2939 
Q 1816 3084 2150 3084 
Q 2853 3084 3261 2657 
Q 3669 2231 3669 1497 
Q 3669 778 3244 343 
Q 2819 -91 2113 -91 
Q 1303 -91 875 529 
Q 447 1150 447 2328 
Q 447 3434 972 4092 
Q 1497 4750 2381 4750 
Q 2619 4750 2861 4703 
Q 3103 4656 3366 4563 
z
" transform="scale(0.015625)"/>
       </defs>
       <use xlink:href="#DejaVuSans-30"/>
       <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
       <use xlink:href="#DejaVuSans-36" x="95.410156"/>
      </g>
     </g>
    </g>
    <g id="xtick_5">
     <g id="line2d_5">
      <g>
       <use xlink:href="#m2c1c4f18cb" x="343.296" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
      </g>
     </g>
     <g id="text_5">
      <!-- 0.8 -->
      <g transform="translate(335.344438 322.182437) scale(0.1 -0.1)">
       <defs>
        <path id="DejaVuSans-38" d="M 2034 2216 
Q 1584 2216 1326 1975 
Q 1069 1734 1069 1313 
Q 1069 891 1326 650 
Q 1584 409 2034 409 
Q 2484 409 2743 651 
Q 3003 894 3003 1313 
Q 3003 1734 2745 1975 
Q 2488 2216 2034 2216 
z
M 1403 2484 
Q 997 2584 770 2862 
Q 544 3141 544 3541 
Q 544 4100 942 4425 
Q 1341 4750 2034 4750 
Q 2731 4750 3128 4425 
Q 3525 4100 3525 3541 
Q 3525 3141 3298 2862 
Q 3072 2584 2669 2484 
Q 3125 2378 3379 2068 
Q 3634 1759 3634 1313 
Q 3634 634 3220 271 
Q 2806 -91 2034 -91 
Q 1263 -91 848 271 
Q 434 634 434 1313 
Q 434 1759 690 2068 
Q 947 2378 1403 2484 
z
M 1172 3481 
Q 1172 3119 1398 2916 
Q 1625 2713 2034 2713 
Q 2441 2713 2670 2916 
Q 2900 3119 2900 3481 
Q 2900 3844 2670 4047 
Q 2441 4250 2034 4250 
Q 1625 4250 1398 4047 
Q 1172 3844 1172 3481 
z
" transform="scale(0.015625)"/>
       </defs>
       <use xlink:href="#DejaVuSans-30"/>
       <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
       <use xlink:href="#DejaVuSans-38" x="95.410156"/>
      </g>
     </g>
    </g>
    <g id="xtick_6">
     <g id="line2d_6">
      <g>
       <use xlink:href="#m2c1c4f18cb" x="414.72" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
      </g>
     </g>
     <g id="text_6">
      <!-- 1.0 -->
      <g transform="translate(406.768438 322.182437) scale(0.1 -0.1)">
       <defs>
        <path id="DejaVuSans-31" d="M 794 531 
L 1825 531 
L 1825 4091 
L 703 3866 
L 703 4441 
L 1819 4666 
L 2450 4666 
L 2450 531 
L 3481 531 
L 3481 0 
L 794 0 
L 794 531 
z
" transform="scale(0.015625)"/>
       </defs>
       <use xlink:href="#DejaVuSans-31"/>
       <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
       <use xlink:href="#DejaVuSans-30" x="95.410156"/>
      </g>
     </g>
    </g>
   </g>
   <g id="matplotlib.axis_2">
    <g id="ytick_1">
     <g id="line2d_7">
      <defs>
       <path id="m305385262c" d="M 0 0 
L -3.5 0 
" style="stroke: #000000; stroke-width: 0.8"/>
      </defs>
      <g>
       <use xlink:href="#m305385262c" x="57.6" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
      </g>
     </g>
     <g id="text_7">
      <!-- 0.0 -->
      <g transform="translate(34.696875 311.383219) scale(0.1 -0.1)">
       <use xlink:href="#DejaVuSans-30"/>
       <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
       <use xlink:href="#DejaVuSans-30" x="95.410156"/>
      </g>
     </g>
    </g>
    <g id="ytick_2">
     <g id="line2d_8">
      <g>
       <use xlink:href="#m305385262c" x="57.6" y="254.3616" style="stroke: #000000; stroke-width: 0.8"/>
      </g>
     </g>
     <g id="text_8">
      <!-- 0.2 -->
      <g transform="translate(34.696875 258.160819) scale(0.1 -0.1)">
       <use xlink:href="#DejaVuSans-30"/>
       <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
       <use xlink:href="#DejaVuSans-32" x="95.410156"/>
      </g>
     </g>
    </g>
    <g id="ytick_3">
     <g id="line2d_9">
      <g>
       <use xlink:href="#m305385262c" x="57.6" y="201.1392" style="stroke: #000000; stroke-width: 0.8"/>
      </g>
     </g>
     <g id="text_9">
      <!-- 0.4 -->
      <g transform="translate(34.696875 204.938419) scale(0.1 -0.1)">
       <use xlink:href="#DejaVuSans-30"/>
       <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
       <use xlink:href="#DejaVuSans-34" x="95.410156"/>
      </g>
     </g>
    </g>
    <g id="ytick_4">
     <g id="line2d_10">
      <g>
       <use xlink:href="#m305385262c" x="57.6" y="147.9168" style="stroke: #000000; stroke-width: 0.8"/>
      </g>
     </g>
     <g id="text_10">
      <!-- 0.6 -->
      <g transform="translate(34.696875 151.716019) scale(0.1 -0.1)">
       <use xlink:href="#DejaVuSans-30"/>
       <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
       <use xlink:href="#DejaVuSans-36" x="95.410156"/>
      </g>
     </g>
    </g>
    <g id="ytick_5">
     <g id="line2d_11">
      <g>
       <use xlink:href="#m305385262c" x="57.6" y="94.6944" style="stroke: #000000; stroke-width: 0.8"/>
      </g>
     </g>
     <g id="text_11">
      <!-- 0.8 -->
      <g transform="translate(34.696875 98.493619) scale(0.1 -0.1)">
       <use xlink:href="#DejaVuSans-30"/>
       <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
       <use xlink:href="#DejaVuSans-38" x="95.410156"/>
      </g>
     </g>
    </g>
    <g id="ytick_6">
     <g id="line2d_12">
      <g>
       <use xlink:href="#m305385262c" x="57.6" y="41.472" style="stroke: #000000; stroke-width: 0.8"/>
      </g>
     </g>
     <g id="text_12">
      <!-- 1.0 -->
      <g transform="translate(34.696875 45.271219) scale(0.1 -0.1)">
       <use xlink:href="#DejaVuSans-31"/>
       <use xlink:href="#DejaVuSans-2e" x="63.623047"/>
       <use xlink:href="#DejaVuSans-30" x="95.410156"/>
      </g>
     </g>
    </g>
   </g>
   <g id="patch_13">
    <path d="M 57.6 307.584 
L 57.6 41.472 
" style="fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square"/>
   </g>
   <g id="patch_14">
    <path d="M 414.72 307.584 
L 414.72 41.472 
" style="fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square"/>
   </g>
   <g id="patch_15">
    <path d="M 57.6 307.584 
L 414.72 307.584 
" style="fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square"/>
   </g>
   <g id="patch_16">
    <path d="M 57.6 41.472 
L 414.72 41.472 
" style="fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square"/>
   </g>
  </g>
 </g>
 <defs>
  <clipPath id="pa361fe6ebe">
   <rect x="57.6" y="41.472" width="357.12" height="266.112"/>
  </clipPath>
 </defs>
</svg>

Additional information

No response

Operating system

No response

Matplotlib Version

3.8.3

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

None

@oscargus
Copy link
Contributor

I think that this holds for any backend, not just SVG, as it seems to stem from:

def draw_path_collection(self, gc, master_transform, paths, *args,
**kwargs):
# We do a little shimmy so that all paths are drawn for each path
# effect in turn. Essentially, we induce recursion (depth 1) which is
# terminated once we have just a single path effect to work with.
if len(self._path_effects) == 1:
# Call the base path effect function - this uses the unoptimised
# approach of calling "draw_path" multiple times.
return super().draw_path_collection(gc, master_transform, paths,
*args, **kwargs)
for path_effect in self._path_effects:
renderer = self.copy_with_path_effect([path_effect])
# Recursively call this method, only next time we will only have
# one path effect.
renderer.draw_path_collection(gc, master_transform, paths,
*args, **kwargs)

Not sure if there are cases where this is needed (in your simple path effect case, it is clearly not), if it is just a way to get code that works with any backend or if this can be simply changed though...

@szsdk
Copy link
Author

szsdk commented Apr 28, 2024

In my case, I want to use matplotlib to generate an artistic plot which contains a lot of polygons (>2000). I got the output SVG file. But basically no SVG viewer can open it.

@tacaswell tacaswell added this to the v3.9.0 milestone Apr 29, 2024
@tacaswell
Copy link
Member

This is fixed by #27906 (and this issue is a duplicate of #27843).

The core problem is diagnosed in #27843 (comment)

@szsdk Can you check with the pre-release pip install --pre matplotlib ?

@szsdk
Copy link
Author

szsdk commented Apr 30, 2024

@tacaswell Thanks. The pre-release solves the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants