Skip to content

[Bug]: Matplotlib clabels too close to the boundary #28865

Open
@Firestar-Reimu

Description

@Firestar-Reimu

Bug summary

Matplotlib clabels too close to the boundary

Code for reproduction

x = np.arange(-10, 10.01, 0.01) + 8
y = np.arange(-10, 10.01, 0.01)

X, Y = np.meshgrid(x, y)

r = np.sqrt(X**2 + Y**2)
theta = np.arctan2(Y, X - 8)
v0 = 233
R = 8
v = v0 * np.sin(theta) * (R / r - 1)

fig, ax = plt.subplots()
ax.set_box_aspect(1)

cs = ax.contour(
    x - 8,
    y,
    v,
    levels=np.arange(-150, 160, 10),
    linewidths=1,
    cmap="coolwarm", # coolwarm
    linestyles="solid",
)
ax.clabel(cs, cs.levels, inline=True, fontsize=8, inline_spacing=10)

plt.colorbar(cs)
plt.show()

Actual outcome

image

You can see that the right side labels are half out of the boundary

Expected outcome

put them further from the boundary

Additional information

I use jupyter notebook and the manual=True does not work

Operating system

Archlinux

Matplotlib Version

3.9.2

Matplotlib Backend

No response

Python version

3.12.2

Jupyter version

7.2.2 (I use vscode-jupyter-plugin)

Installation

conda

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions