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

[ENH]: Please add matplotlib.patches.RoundedRectangle #27969

Open
dipeshSam opened this issue Mar 23, 2024 · 2 comments
Open

[ENH]: Please add matplotlib.patches.RoundedRectangle #27969

dipeshSam opened this issue Mar 23, 2024 · 2 comments
Labels
Documentation: API files in lib/ and doc/api New feature

Comments

@dipeshSam
Copy link

dipeshSam commented Mar 23, 2024

Problem

  • I'm always frustrated when matplotlib.patches.Rectangle does not round the corners of the rectangle because it requires padding and other rectangle-irrelevant values.
  • I would like it if there is a clsas or method like matplotlib.patches.RoundedRectangle(xy, width, height, corner_radius, **kwargs) that can take any radius <= min(width, height) because matplotlib.patches.FancyBboxPatch does not round the rectangle as much as possible.
  • Here is a sample image of what I am asking for
    rect_showing

Proposed solution

Please add/implement matplotlib.patches.RoundedRectangle(xy, width, height, corner_radius, **kwargs)

@saranti
Copy link
Contributor

saranti commented Mar 23, 2024

You can round the edges a fair amount using the boxstyle parameter
e.g.

import matplotlib.pyplot as plt
import matplotlib.patches as patches

fig, ax = plt.subplots()
rect = patches.FancyBboxPatch((.2, .2),
                              boxstyle="round, pad=0.1, rounding_size=0.2",
                              width=.4,
                              height=.4,
                              fill=True)
ax.add_patch(rect)
ax.set_aspect('equal')
plt.show()

Screenshot 2024-03-24 011123

@dipeshSam
Copy link
Author

dipeshSam commented Mar 23, 2024

@saranti Wow nice! Thank you brother. Could you please tell me what's relation between the two: pad=0.1 and rounding_size=0.2?

I mean, how rounding_size requires pad value or how pad value affects rounding_size?

Let, given that width and height are equal. Then, if rounding_size = width/2 must produce a circle of the same radius as rounding_size.

Thanks again.

@oscargus oscargus added the Documentation: API files in lib/ and doc/api label Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation: API files in lib/ and doc/api New feature
Projects
None yet
Development

No branches or pull requests

3 participants