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

Python-docx vertically align rectangle and paragraph. #1469

Open
MWatson-UMC opened this issue Feb 20, 2025 · 0 comments
Open

Python-docx vertically align rectangle and paragraph. #1469

MWatson-UMC opened this issue Feb 20, 2025 · 0 comments

Comments

@MWatson-UMC
Copy link

I am trying to align the right edge of a rectangle with the right edge of the paragraph of text below the rectangle.. Inside the rectangle there is an image. I can't make this work. TIA. Mark

fig, ax = plt.subplots(figsize=(6.5, 2.5)) # Adjust figure size for better spacing #original figsize was 7,2.5

rectangle = Rectangle(
(0.02, 0), # Small shift to align the left edge
0.80, # Adjust width so the right side aligns perfectly
1, # Full height remains the same
transform=fig.transFigure,
fill=False,
edgecolor="lightgray",
linewidth=1
)
fig.patches.append(rectangle)

Adjust overall chart position (shifts chart + frame together)

plt.subplots_adjust(
left=-0.5,  # Decrease this value to move chart left (lower value means less indentation)
right=0.5,  # Keep the right margin tight    
#left=0.05,  # Decrease this value to move chart left (lower value means less indentation)
#right=0.95,  # Keep the right margin tight
top=0.85,    # Top margin remains unchanged
bottom=0.4   # Adjust bottom margin for spacing

)
# Manually adjust the chart position
box = ax.get_position()
ax.set_position([
box.x0 - 0.05, # Shift chart left (increase to move further left)
box.y0,
box.width,
box.height
])

# Adjust the rectangle around the chart
rectangle.set_bounds(
    -0.05,  # Shift rectangle left
    0,      # Y-coordinate remains the same
    1.05,   # Slightly adjust width to align right edge
    1       # Height remains the same
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant