- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.2k
Description
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
)