making subplots more square

hi all,

i have a series of subplots organized in a column (3x1). i noticed that if i plot them then matplotlib tends to make the x-axis long and the y-axis short, so the plot is really rectangular. how can i make it more square? if i do:

f = figure(figsize=(7,6), dpi=100)
p1 = subplot(3,1,1)
plot(…)

make axes square

p1.set_aspect(‘equal’)

p2 = subplot(3,1,2)
plot(…)
p2.set_aspect(‘equal’)

etc for third subplot…

then the subplots i get are square, but very small and squished compared to the space they have in the figure (ie what i set in figsize.) how can i fix this? i just want to have square axes, but have each subplot take up as much space as it would if i didnt set square axes… it works fine for the rectangular axes case.

per freem wrote:

hi all,

i have a series of subplots organized in a column (3x1). i noticed that if i plot them then matplotlib tends to make the x-axis long and the y-axis short, so the plot is really rectangular. how can i make it more square? if i do:

f = figure(figsize=(7,6), dpi=100)
p1 = subplot(3,1,1)
plot(....)
# make axes square
p1.set_aspect('equal')

p2 = subplot(3,1,2)
plot(....)
p2.set_aspect('equal')

# etc for third subplot...

then the subplots i get are square, but very small and squished compared to the space they have in the figure (ie what i set in figsize.) how can i fix this? i just want to have square axes, but have each subplot take up as much space as it would if i didnt set square axes... it works fine for the rectangular axes case.

Maybe what you are looking for is
p1.set_aspect('equal', adjustable='datalim')

It is not clear from your message, but try the modification above and see if it does what you want.

Eric

hi eric,

i tried your suggestion but it still did not work. here’s a code snippet that demonstrates what i am trying to do:

import matplotlib.pyplot as plt
from scipy import *

my_fig = plt.figure(figsize=(7,6), dpi=100)
plot_ax1 = plt.subplot(3,1,1)
a = rand(100)
b = rand(100) + rand()
plt.scatter(a, b)
plot_ax1.set(xticklabels=[])
plot_ax1.set_aspect(‘equal’, adjustable=‘box’)
plt.savefig(‘myplot.pdf’)

when i run this, i get a small square scatter plot in the middle of the page. i want this plot to be scaled to be bigger. if i remove the set_aspect() call, the plot becomes bigger in the horizontal direction, and is rectangular.

any ideas how to fix this? thanks again.

···

On Sun, May 24, 2009 at 9:24 PM, Eric Firing <efiring@…202…> wrote:

per freem wrote:

hi all,

i have a series of subplots organized in a column (3x1). i noticed that if i plot them then matplotlib tends to make the x-axis long and the y-axis short, so the plot is really rectangular. how can i make it more square? if i do:

f = figure(figsize=(7,6), dpi=100)

p1 = subplot(3,1,1)

plot(…)

make axes square

p1.set_aspect(‘equal’)

p2 = subplot(3,1,2)

plot(…)

p2.set_aspect(‘equal’)

etc for third subplot…

then the subplots i get are square, but very small and squished compared to the space they have in the figure (ie what i set in figsize.) how can i fix this? i just want to have square axes, but have each subplot take up as much space as it would if i didnt set square axes… it works fine for the rectangular axes case.

Maybe what you are looking for is

p1.set_aspect(‘equal’, adjustable=‘datalim’)

It is not clear from your message, but try the modification above and see if it does what you want.

Eric

per freem wrote:

hi eric,

i tried your suggestion but it still did not work. here's a code snippet that demonstrates what i am trying to do:

No, I'm still baffled. If you stack 3 subplots vertically in a figure 6 inches high, they are going to be small. You can fiddle with their sizes a bit by using subplots_adjust, but they are still going to be small--less than 2 inches high. What physical dimensions do you want, when you say you want the plot to be "scaled bigger"?

Eric

···

import matplotlib.pyplot as plt from scipy import *
                                                                                     
my_fig = plt.figure(figsize=(7,6), dpi=100) plot_ax1 = plt.subplot(3,1,1) a = rand(100)

b = rand(100) + rand() plt.scatter(a, b) plot_ax1.set(xticklabels=[])

plot_ax1.set_aspect('equal', adjustable='box') plt.savefig('myplot.pdf')

when i run this, i get a small square scatter plot in the middle of the page. i want this plot to be scaled to be bigger. if i remove the set_aspect() call, the plot becomes bigger in the horizontal direction, and is rectangular.

any ideas how to fix this? thanks again.

On Sun, May 24, 2009 at 9:24 PM, Eric Firing <efiring@…202… > <mailto:efiring@…202…>> wrote:

    per freem wrote:

        hi all,

        i have a series of subplots organized in a column (3x1). i
        noticed that if i plot them then matplotlib tends to make the
        x-axis long and the y-axis short, so the plot is really
        rectangular. how can i make it more square? if i do:

        f = figure(figsize=(7,6), dpi=100)
        p1 = subplot(3,1,1)
        plot(....)
        # make axes square
        p1.set_aspect('equal')

        p2 = subplot(3,1,2)
        plot(....)
        p2.set_aspect('equal')

        # etc for third subplot...

        then the subplots i get are square, but very small and squished
        compared to the space they have in the figure (ie what i set in
        figsize.) how can i fix this? i just want to have square axes,
        but have each subplot take up as much space as it would if i
        didnt set square axes... it works fine for the rectangular axes
        case.

    Maybe what you are looking for is
    p1.set_aspect('equal', adjustable='datalim')

    It is not clear from your message, but try the modification above
    and see if it does what you want.

    Eric