<p dir="auto">The following code snippet takes coordinates for a hand, and clips it to a rectangular window.  Of the returned polygon, the endpoints are duplicated.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from matplotlib import path, transforms
import matplotlib.pyplot as plt
import numpy as np

hand = np.array(
    [[ 1.64516129,  1.16145833 ],
     [ 1.64516129,  1.59375    ],
     [ 1.35080645,  1.921875   ],
     [ 1.375     ,  2.18229167 ],
     [ 1.68548387,  1.9375     ],
     [ 1.60887097,  2.55208333 ],
     [ 1.68548387,  2.69791667 ],
     [ 1.76209677,  2.56770833 ],
     [ 1.83064516,  1.97395833 ],
     [ 1.89516129,  2.75       ],
     [ 1.9516129 ,  2.84895833 ],
     [ 2.01209677,  2.76041667 ],
     [ 1.99193548,  1.99479167 ],
     [ 2.11290323,  2.63020833 ],
     [ 2.2016129 ,  2.734375   ],
     [ 2.25403226,  2.60416667 ],
     [ 2.14919355,  1.953125   ],
     [ 2.30645161,  2.36979167 ],
     [ 2.39112903,  2.36979167 ],
     [ 2.41532258,  2.1875     ],
     [ 2.1733871 ,  1.703125   ],
     [ 2.07782258,  1.16666667 ]])

(r0, c0, r1, c1) = (1.0, 1.5, 2.1, 2.5)

poly = path.Path(np.vstack((hand[:, 1], hand[:, 0])).T, closed=True)
clip_rect = transforms.Bbox([[r0, c0], [r1, c1]])
poly_clipped = poly.clip_to_bbox(clip_rect).to_polygons()[0]

print(len(poly_clipped[:, 0]), len(poly_clipped[:, 1]))

plt.plot(hand[:, 0], hand[:, 1], 'r-')
plt.plot(poly_clipped[:, 1], poly_clipped[:, 0], 'go-')
plt.show()

print(poly_clipped[-2:, :])"><pre class="notranslate"><code class="notranslate">from matplotlib import path, transforms
import matplotlib.pyplot as plt
import numpy as np

hand = np.array(
    [[ 1.64516129,  1.16145833 ],
     [ 1.64516129,  1.59375    ],
     [ 1.35080645,  1.921875   ],
     [ 1.375     ,  2.18229167 ],
     [ 1.68548387,  1.9375     ],
     [ 1.60887097,  2.55208333 ],
     [ 1.68548387,  2.69791667 ],
     [ 1.76209677,  2.56770833 ],
     [ 1.83064516,  1.97395833 ],
     [ 1.89516129,  2.75       ],
     [ 1.9516129 ,  2.84895833 ],
     [ 2.01209677,  2.76041667 ],
     [ 1.99193548,  1.99479167 ],
     [ 2.11290323,  2.63020833 ],
     [ 2.2016129 ,  2.734375   ],
     [ 2.25403226,  2.60416667 ],
     [ 2.14919355,  1.953125   ],
     [ 2.30645161,  2.36979167 ],
     [ 2.39112903,  2.36979167 ],
     [ 2.41532258,  2.1875     ],
     [ 2.1733871 ,  1.703125   ],
     [ 2.07782258,  1.16666667 ]])

(r0, c0, r1, c1) = (1.0, 1.5, 2.1, 2.5)

poly = path.Path(np.vstack((hand[:, 1], hand[:, 0])).T, closed=True)
clip_rect = transforms.Bbox([[r0, c0], [r1, c1]])
poly_clipped = poly.clip_to_bbox(clip_rect).to_polygons()[0]

print(len(poly_clipped[:, 0]), len(poly_clipped[:, 1]))

plt.plot(hand[:, 0], hand[:, 1], 'r-')
plt.plot(poly_clipped[:, 1], poly_clipped[:, 0], 'go-')
plt.show()

print(poly_clipped[-2:, :])
</code></pre></div>
<h3 dir="auto">Problem</h3>
<p dir="auto">Trying to combine subplot_mosaic with axes using various different projections (e.g. one rectilinear axes and one polar axes and one 3d axes) has been requested a few times (once in the original subplot_mosaic thread IIRC, and in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="915354311" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/20392" data-hovercard-type="issue" data-hovercard-url="/matplotlib/matplotlib/issues/20392/hovercard" href="https://github.com/matplotlib/matplotlib/issues/20392">#20392</a> too), and it's something I would recently have been happy to have, too.</p>
<p dir="auto">Pushing projections directly into subplot_mosaic seems ripe for API bloat, but perhaps another solution would be to add <code class="notranslate">figure.gridspec_mosaic(...)</code> which takes the same arguments as subplot_mosaic, but returns a dict of <em>subplotspecs</em>, such that one can do something like</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="specs = fig.gridspec_mosaic(...)
d = {
    &quot;foo&quot;: fig.add_subplot(specs[&quot;foo&quot;], projection=...),
    &quot;bar&quot;: fig.add_subplot(specs[&quot;bar&quot;], projection=...),
    ...
}"><pre class="notranslate"><code class="notranslate">specs = fig.gridspec_mosaic(...)
d = {
    "foo": fig.add_subplot(specs["foo"], projection=...),
    "bar": fig.add_subplot(specs["bar"], projection=...),
    ...
}
</code></pre></div>
<p dir="auto">As a side point, I do find the repetition of <code class="notranslate">fig</code> in each call to add_subplot a bit jarring (as the underlying gridspec is bound to the figure, so that information is actually redundant).  Back in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="402870906" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/13280" data-hovercard-type="pull_request" data-hovercard-url="/matplotlib/matplotlib/pull/13280/hovercard" href="https://github.com/matplotlib/matplotlib/pull/13280">#13280</a> I had proposed to add SubplotSpec.add_subplot() (adding to the figure to which the gridspec is bound), which would allow one to write, here,</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="specs = fig.gridspec_mosaic(...)
d = {
    &quot;foo&quot;: specs[&quot;foo&quot;].add_subplot(projection=...),
    &quot;bar&quot;: specs[&quot;bar&quot;].add_subplot(projection=...),
    ...
}"><pre class="notranslate"><code class="notranslate">specs = fig.gridspec_mosaic(...)
d = {
    "foo": specs["foo"].add_subplot(projection=...),
    "bar": specs["bar"].add_subplot(projection=...),
    ...
}
</code></pre></div>
<p dir="auto">but that idea got shot down back then and even if we decide not to revisit it, even the first form would be nice to have.</p>
<p dir="auto">Thoughts?</p>
<h3 dir="auto">Proposed solution</h3>
<p dir="auto"><em>No response</em></p>