legend missed one dataset

Hello,
the following script creates a legend for only two instead of three datasets.

···

-----------
from pylab import *
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)

for i in [[2,2], [2,3], [4.2,3.5]]:
   print i[0],i[1]
   plt.plot(i[0],i[1],'o')

ax.grid(True)
plt.legend(('Model length', 'Data length'),
            'best', shadow=True, fancybox=True)

plt.show()
-----------------

What did I wrong.

Thank you in advance.

You have plotted three lines, but only provided legend labels for two of them. Try:

plt.legend(('Model length', 'Data length', 'Something else'),
             'best', shadow=True, fancybox=True)

Mike

···

On 08/24/2010 06:33 AM, xyz wrote:

Hello,
the following script creates a legend for only two instead of three
datasets.
-----------
from pylab import *
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)

for i in [[2,2], [2,3], [4.2,3.5]]:
    print i[0],i[1]
    plt.plot(i[0],i[1],'o')

ax.grid(True)
plt.legend(('Model length', 'Data length'),
             'best', shadow=True, fancybox=True)

plt.show()
-----------------

What did I wrong.

Thank you in advance.

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options
   
--
Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA

Thank you, but why the coordinates start from 2 and not from 0 with the following code?

from pylab import *
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)

for i in [[2,2], [2,3], [4.2,3.5]]:
   print i[0],i[1]
   plt.plot(i[0],i[1],'o')

ax.grid(True)
plt.legend(['Model length', 'Data length', 'test'],
            'best', shadow=True, fancybox=True)

plt.show()

How is it possible that the coordinates start from 0?

···

On 24/08/10 22:43, Michael Droettboom wrote:

You have plotted three lines, but only provided legend labels for two of
them. Try:

plt.legend(('Model length', 'Data length', 'Something else'),
              'best', shadow=True, fancybox=True)

Mike

On 08/24/2010 06:33 AM, xyz wrote:
   

Hello,
the following script creates a legend for only two instead of three
datasets.
-----------
from pylab import *
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)

for i in [[2,2], [2,3], [4.2,3.5]]:
     print i[0],i[1]
     plt.plot(i[0],i[1],'o')

ax.grid(True)
plt.legend(('Model length', 'Data length'),
              'best', shadow=True, fancybox=True)

plt.show()
-----------------

What did I wrong.

Thank you in advance.

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

I believe you are asking why the x axis starts at 2? This is because matplotlib will automatically set the limits of your plot to show all of your data. If you can control the axes yourself by calling set_xlim() and/or set_ylim().

ax.set_xlim(0.0, 5.0)

would set the limits of your x axis to 0.0 and 5.0. You can also do

ax.set_xlim(left=0.0)

to control only the left end of the axis (letting the right end be automatically set).

I hope that helps!
Ben Root

···

On Wed, Aug 25, 2010 at 4:53 AM, xyz <mitlox@…269…> wrote:

Thank you, but why the coordinates start from 2 and not from 0 with the

following code?

from pylab import *

import matplotlib.pyplot as plt

fig = plt.figure()

ax = fig.add_subplot(111)

for i in [[2,2], [2,3], [4.2,3.5]]:

print i[0],i[1]

plt.plot(i[0],i[1],‘o’)

ax.grid(True)

plt.legend([‘Model length’, ‘Data length’, ‘test’],
‘best’, shadow=True, fancybox=True)

plt.show()

How is it possible that the coordinates start from 0?

Thank you it works, but ax.set_xlim(left=0.0) does not work only
ax.set_xlim(0.0) works.

···

On 26/08/10 01:15, Benjamin Root wrote:

I believe you are asking why the x axis starts at 2? This is because matplotlib will automatically set the limits of your plot to show all of your data. If you can control the axes yourself by calling set_xlim() and/or set_ylim().

ax.set_xlim(0.0, 5.0)

would set the limits of your x axis to 0.0 and 5.0. You can also do

ax.set_xlim(left=0.0)

to control only the left end of the axis (letting the right end be automatically set).

I hope that helps!
Ben Root

That's becaues that only works for SVN trunk. The keyword args 'left'
and 'right' have been added as synonyms for xmin and xmax,
respectively. For your release, try:

ax.set_xlim(xmin=0.0)

Ryan

···

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

On 26/08/10 01:15, Benjamin Root wrote:

I believe you are asking why the x axis starts at 2? This is because
matplotlib will automatically set the limits of your plot to show all
of your data. If you can control the axes yourself by calling
set_xlim() and/or set_ylim().

ax.set_xlim(0.0, 5.0)

would set the limits of your x axis to 0.0 and 5.0. You can also do

ax.set_xlim(left=0.0)

to control only the left end of the axis (letting the right end be
automatically set).

I hope that helps!
Ben Root

Thank you it works, but ax.set_xlim(left=0.0) does not work only
ax.set_xlim(0.0) works.

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma