Fixing axes for imshow plot on top of a figure

I'm trying to plot an image on top of a Figure, but imshow seems to always
distort the size of the axes. What I want is that the lower part of the top
image stay always in the same position, for any image height

This minimal example shows my issue

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_axes([0.1, 0, 1, 1])

# Top figure aligned with the bottom figure
# keeping the same width (?)
ax2 = fig.add_axes([0.1, 1, 1, 1])
ax2.set_xticks([])

# Depending on the number of rows or columns
# the top image will be moved further to the top
# or will be stretched if rows > columns
# I dont know how to control this to stay always
# with the same separation with respect
# to the bottom figure and keeping the same width
# (so the frame is the same width than the bottom figure)
im = np.random.rand(10, 30)
ax2.imshow(im)
plt.plot()

If it is possible to

I would prefer to avoid using subplots or grid, since I have already
specified a lot of things using the add_axes method.

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Fixing-axes-for-imshow-plot-on-top-of-a-figure-tp45579.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

I do not think fig.add_axes([0.1, 1, 1, 1]) makes any sense. The docstring says:

fig.add_axes(*args, **kwargs)

Add an axes at position *rect* [*left*, *bottom*, *width*,
*height*] where all quantities are in fractions of figure
width and height.

If bottom and height are both 1 you need the height of the figure to
be 2 in fractions of figure height. This means 1 must equal 2 and then
Bertrand Russel must be the Pope[1].

Goyo

[1] http://ceadserv1.nku.edu/longa//classes/mat385_resources/docs/russellpope.html

2015-05-20 13:43 GMT+02:00 aradand <aradan.d@...287...>:

···

I'm trying to plot an image on top of a Figure, but imshow seems to always
distort the size of the axes. What I want is that the lower part of the top
image stay always in the same position, for any image height

This minimal example shows my issue

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_axes([0.1, 0, 1, 1])

# Top figure aligned with the bottom figure
# keeping the same width (?)
ax2 = fig.add_axes([0.1, 1, 1, 1])
ax2.set_xticks()

# Depending on the number of rows or columns
# the top image will be moved further to the top
# or will be stretched if rows > columns
# I dont know how to control this to stay always
# with the same separation with respect
# to the bottom figure and keeping the same width
# (so the frame is the same width than the bottom figure)
im = np.random.rand(10, 30)
ax2.imshow(im)
plt.plot()

If it is possible to

I would prefer to avoid using subplots or grid, since I have already
specified a lot of things using the add_axes method.

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Fixing-axes-for-imshow-plot-on-top-of-a-figure-tp45579.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
Application Monitor Software & Tools - ManageEngine Applications Manager
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

I think you want figimage(): http://matplotlib.org/examples/pylab_examples/figimage_demo.html

I use it all the time for adding the company’s logo to graphs. Keep in mind that it will plot the unsampled version of the image, so the final result depends on the figure size and resolution.

I hope that helps!

Ben Root

···

On Wed, May 20, 2015 at 7:43 AM, aradand <aradan.d@…287…> wrote:

I’m trying to plot an image on top of a Figure, but imshow seems to always

distort the size of the axes. What I want is that the lower part of the top

image stay always in the same position, for any image height

This minimal example shows my issue

import matplotlib.pyplot as plt

import numpy as np

fig = plt.figure()

ax = fig.add_axes([0.1, 0, 1, 1])

Top figure aligned with the bottom figure

keeping the same width (?)

ax2 = fig.add_axes([0.1, 1, 1, 1])

ax2.set_xticks()

Depending on the number of rows or columns

the top image will be moved further to the top

or will be stretched if rows > columns

I dont know how to control this to stay always

with the same separation with respect

to the bottom figure and keeping the same width

(so the frame is the same width than the bottom figure)

im = np.random.rand(10, 30)

ax2.imshow(im)

plt.plot()

If it is possible to

I would prefer to avoid using subplots or grid, since I have already

specified a lot of things using the add_axes method.

View this message in context: http://matplotlib.1069221.n5.nabble.com/Fixing-axes-for-imshow-plot-on-top-of-a-figure-tp45579.html

Sent from the matplotlib - users mailing list archive at Nabble.com.


One dashboard for servers and applications across Physical-Virtual-Cloud

Widest out-of-the-box monitoring support with 50+ applications

Performance metrics, stats and reports that give you Actionable Insights

Deep dive visibility with transaction tracing using APM Insight.

http://ad.doubleclick.net/ddm/clk/290420510;117567292;y


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users