From: xyz <mi...@op...> - 2010-08-24 10:34:04
|
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. |
From: Michael D. <md...@st...> - 2010-08-24 12:43:36
|
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 > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- Michael Droettboom Science Software Branch Space Telescope Science Institute Baltimore, Maryland, USA |
From: xyz <mi...@op...> - 2010-08-25 09:54:11
|
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 >> Mat...@li... >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> >> > > |
From: Benjamin R. <ben...@ou...> - 2010-08-25 15:21:34
|
On Wed, Aug 25, 2010 at 4:53 AM, xyz <mi...@op...> 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? > > > 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 |
From: xyz <mi...@op...> - 2010-08-26 11:19:12
|
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. |
From: Ryan M. <rm...@gm...> - 2010-08-26 13:41:53
|
On Thu, Aug 26, 2010 at 6:18 AM, xyz <mi...@op...> 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. 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 -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma |