optimal size with figsize

Hello,
What is the best way to create an automatically optimal size for picture with figsize?

from pylab import *
import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]
y1 = [20, 24, 8, 4, 12, 22, 31, 25, 15, 28, 12, 27, 22, 22, 27, 14, 32, 28, 8, 17, 2, 8, 29, 13, 14, 20, 11, 28, 8]
point_labels1 = ['A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1']

#fig = plt.figure(figsize=(40,40))
ax = fig.add_subplot(111)

ax.set_title('The red point should be on the path')

plt.plot(x, y1, 'bo', x, y2, 'go')
ax.grid(True)

# rotates and right aligns the x labels, and moves the bottom of the
# axes up to make room for them
fig.autofmt_xdate()

# set x and y labels
plt.xticks(range(0, 40, 1))

#ax.set_xticks(4.5)
plt.yticks(range(0, 40, 1))
plt.xlabel('Longitude')
plt.ylabel('Latitude')
plt.legend(('Model length', 'Data length'),
            'best', shadow=True, fancybox=True)

for i, label in enumerate(y1):
   plt.text (x[i], y1[i]+0.2, label,
             horizontalalignment='center' )

plt.show()

Thank you in advance.

Maybe the .set_aspect() function can help you?

http://matplotlib.sourceforge.net/api/axes_api.html?highlight=set_aspect#matplotlib.axes.Axes.set_aspect

I should point out that there has been some changes to set_aspect(), so if you are not using version 1.0 of mpl, then you need to check your version of the documentation.

I hope that helps!
Ben Root

···

On Thu, Aug 26, 2010 at 6:55 AM, xyz <mitlox@…269…> wrote:

Hello,

What is the best way to create an automatically optimal size for picture

with figsize?

from pylab import *

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,

20, 21, 22, 23, 24, 25, 26, 27, 28, 29]

y1 = [20, 24, 8, 4, 12, 22, 31, 25, 15, 28, 12, 27, 22, 22, 27, 14, 32,

28, 8, 17, 2, 8, 29, 13, 14, 20, 11, 28, 8]

point_labels1 = [‘A=1’, ‘A=1’, ‘A=1’, ‘A=1’, ‘A=1’, ‘A=1’, ‘A=1’, ‘A=1’,

‘A=1’, ‘A=1’, ‘A=1’, ‘A=1’, ‘A=1’, ‘A=1’, ‘A=1’, ‘A=1’, ‘A=1’, ‘A=1’,

‘A=1’, ‘A=1’, ‘A=1’, ‘A=1’, ‘A=1’, ‘A=1’, ‘A=1’, ‘A=1’, ‘A=1’, ‘A=1’,

‘A=1’]

#fig = plt.figure(figsize=(40,40))

ax = fig.add_subplot(111)

ax.set_title(‘The red point should be on the path’)

plt.plot(x, y1, ‘bo’, x, y2, ‘go’)

ax.grid(True)

rotates and right aligns the x labels, and moves the bottom of the

axes up to make room for them

fig.autofmt_xdate()

set x and y labels

plt.xticks(range(0, 40, 1))

#ax.set_xticks(4.5)

plt.yticks(range(0, 40, 1))

plt.xlabel(‘Longitude’)

plt.ylabel(‘Latitude’)

plt.legend((‘Model length’, ‘Data length’),

        'best', shadow=True, fancybox=True)

for i, label in enumerate(y1):

plt.text (x[i], y1[i]+0.2, label,

         horizontalalignment='center' )

plt.show()

Thank you in advance.