Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8058153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:15:46+00:00 2026-06-05T09:15:46+00:00

EDIT: I found myself an answer (see below) how to align the images within

  • 0

EDIT:

I found myself an answer (see below) how to align the images within their subplots:

for ax in axes:
    ax.set_anchor('W')

EDIT END

I have some data I plot with imshow. It’s long in x direction, so I break it into multiple lines by plotting slices of the data in vertically stacked subplots. I am happy with the result but for the last subplot (not as wide as the others) which I want left aligned with the others.

The code below is tested with Python 2.7.1 and matplotlib 1.2.x.

#! /usr/bin/env python

import matplotlib.pyplot as plt
import numpy as np

x_slice = [0,3]
y_slices = [[0,10],[10,20],[20,30],[30,35]]
d = np.arange(35*3).reshape((35,3)).T
vmin = d.min()
vmax = d.max()
fig, axes = plt.subplots(len(y_slices), 1)


for i, s in enumerate(y_slices):
    axes[i].imshow( 
        d[ x_slice[0]:x_slice[1], s[0]:s[1] ], 
        vmin=vmin, vmax=vmax,
        aspect='equal',
        interpolation='none'
    )

plt.show()

results in

vertically stacked subplots, last centered

Given the tip by Zhenya I played around with axis.get/set_position. I tried to half the width but I don’t understand the effect it has

for ax in axes:
    print ax.get_position()

p3 = axes[3].get_position().get_points()
x0, y0 = p3[0]
x1, y1 = p3[1]
# [left, bottom, width, height]
axes[3].set_position([x0, y0, (x1-x0)/2, y1-y0])

enter image description here

get_position gives me the bbox of each subplot:

for ax in axes:
    print ax.get_position()

Bbox(array([[ 0.125     ,  0.72608696],
            [ 0.9       ,  0.9       ]]))
Bbox(array([[ 0.125     ,  0.5173913 ],
            [ 0.9       ,  0.69130435]]))
Bbox(array([[ 0.125     ,  0.30869565],
            [ 0.9       ,  0.4826087 ]]))
Bbox(array([[ 0.125     ,  0.1       ],
            [ 0.9       ,  0.27391304]]))

so all the subplots have the exact same horizontal extent (0.125 to 0.9). Judging from the narrower 4th subplot the image inside the subplot is somehow centered.

Let’s look at the AxesImage objects:

for ax in axes:
    print ax.images[0]

AxesImage(80,348.522;496x83.4783)
AxesImage(80,248.348;496x83.4783)
AxesImage(80,148.174;496x83.4783)
AxesImage(80,48;496x83.4783)

again, the same horizontal extent for the 4th image too.

Next try AxesImage.get_extent():

for ax in axes:
    print ax.images[0].get_extent()

# [left, right, bottom, top]
(-0.5, 9.5, 2.5, -0.5)
(-0.5, 9.5, 2.5, -0.5)
(-0.5, 9.5, 2.5, -0.5)
(-0.5, 4.5, 2.5, -0.5)

there is a difference (right) but the left value is the same for all so why is the 4th one centered then?

EDIT: They are all centered…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:15:48+00:00Added an answer on June 5, 2026 at 9:15 am

    Axis.set_anchor works so far (I just hope I don’t have to adjust too much manually now):

    for ax in axes:
        ax.set_anchor('W')
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

* EDIT: I found the answer to the memory leak myself, and posted it
EDIT : I have found how to post headers, and I know how to
I'm currently using the below script which I found online: ######################################### #### BEGIN EDIT
EDIT: Answer found! Thank you very much people, a lot of answers worked, I
I'm building a fairly calculation-heavy cart for a fabric store and have found myself
I have recently found myself on a Linux computer and am liking it so
I have found myself in a situation where I have a method on a
[edit] Found the solution. Reinstall EVERYTHING - xcode, mono, monodevelop and monotouch. Now it
EDIT : I found classloader leak in my webapplication. It boils down to 3rd
EDIT: I've found what's causing the issue, but I don't know why and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.