Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Rightclick on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: hettling <hettling@fe...>  20100517 14:54:07

Dear all, I'm struggling with the following problem plotting my data: I have a figure with two panels next to each other, which I want to label 'A' and 'B'. I want to leftjustify my panel labels, but not to the box that contains the plot, but to the yaxis label. I played around with 'text()' and 'title()', but did not find a good solution except for giving the coordinates manually to 'text()'. This would be very inconvenient though, because I have many different plots on different scales. Here is what I tried: ###Code import scipy import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(121) plt.plot(scipy.sin(scipy.arange(1,100, 0.001))) plt.xlabel('xlabel') plt.ylabel("ylabel") plt.text(0,1,"A", fontsize=14, transform=ax.transAxes) ax = fig.add_subplot(122) plt.plot(scipy.cos(scipy.arange(1,100, 0.001))) plt.text(0,1,"B", fontsize=14, transform=ax.transAxes) plt.xlabel('xlabel') ###End Code So the texts 'A' and 'B' should be a little bit higher and more to the left. The 'A' I want to align with the yaxis label of the left plot, the 'B' with the values of the yaxis of the right plot. I hope my question is clear, I will appreciate any help! Thanks in advance, Hannes 
From: Ryan May <rmay31@gm...>  20100518 15:06:38

On Mon, May 17, 2010 at 10:08 AM, hettling <hettling@...> wrote: > Dear all, > > I'm struggling with the following problem plotting my data: > > I have a figure with two panels next to each other, which I want to > label 'A' and 'B'. I want to leftjustify my panel labels, but not to > the box that contains the plot, but to the yaxis label. I played around > with 'text()' and 'title()', but did not find a good solution except for > giving the coordinates manually to 'text()'. This would be very > inconvenient though, because I have many different plots on different > scales. > Here is what I tried: > > ###Code > import scipy > import matplotlib.pyplot as plt > > fig = plt.figure() > ax = fig.add_subplot(121) > plt.plot(scipy.sin(scipy.arange(1,100, 0.001))) > plt.xlabel('xlabel') > plt.ylabel("ylabel") > plt.text(0,1,"A", fontsize=14, transform=ax.transAxes) > > ax = fig.add_subplot(122) > plt.plot(scipy.cos(scipy.arange(1,100, 0.001))) > plt.text(0,1,"B", fontsize=14, transform=ax.transAxes) > plt.xlabel('xlabel') > ###End Code > > So the texts 'A' and 'B' should be a little bit higher and more to the > left. The 'A' I want to align with the yaxis label of the left plot, > the 'B' with the values of the yaxis of the right plot. I haven't thought through the solution completely, but my intuition says that this might be helpful: http://matplotlib.sourceforge.net/examples/pylab_examples/anchored_artists.html http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html#anchoredartists These examples show ways of anchoring artists (like Text) to certain locations. It's probably your best bet for getting what you want. Ryan  Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma 
From: JaeJoon Lee <lee.j.joon@gm...>  20100518 17:34:58

This can be done relatively easily with the current svn version of matplotlib (r8319). Below is the modified version of your code. See http://matplotlib.sourceforge.net/trunkdocs/users/annotations_guide.html#usingcomplexcoordinatewithannotation for how the annotation works. While this is certainly possible with the released version, but it will require you to write a few tens of lines of code. Basically, you need create a custom Text class that update its position during the drawing time. Regards, JJ ###Code import scipy import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(121) plt.plot(scipy.sin(scipy.arange(1,100, 0.001))) plt.xlabel('xlabel') yl = plt.ylabel("ylabel") plt.annotate("A", (0,1.), xycoords=(yl, "axes fraction"), xytext=(0, 14), textcoords="offset points", fontsize=14) ax = fig.add_subplot(122) plt.plot(scipy.cos(scipy.arange(1,100, 0.001))) plt.xlabel('xlabel') my_ticklabel = ax.get_yticklabels()[2] # Note that there is no guarantee that all ticklabels are drawn. plt.annotate("B", (0,1.), xycoords=(my_ticklabel, "axes fraction"), xytext=(0, 14), textcoords="offset points", fontsize=14) ###End Code On Mon, May 17, 2010 at 11:08 AM, hettling <hettling@...> wrote: > Dear all, > > I'm struggling with the following problem plotting my data: > > I have a figure with two panels next to each other, which I want to > label 'A' and 'B'. I want to leftjustify my panel labels, but not to > the box that contains the plot, but to the yaxis label. I played around > with 'text()' and 'title()', but did not find a good solution except for > giving the coordinates manually to 'text()'. This would be very > inconvenient though, because I have many different plots on different > scales. > Here is what I tried: > > ###Code > import scipy > import matplotlib.pyplot as plt > > fig = plt.figure() > ax = fig.add_subplot(121) > plt.plot(scipy.sin(scipy.arange(1,100, 0.001))) > plt.xlabel('xlabel') > plt.ylabel("ylabel") > plt.text(0,1,"A", fontsize=14, transform=ax.transAxes) > > ax = fig.add_subplot(122) > plt.plot(scipy.cos(scipy.arange(1,100, 0.001))) > plt.text(0,1,"B", fontsize=14, transform=ax.transAxes) > plt.xlabel('xlabel') > ###End Code > > So the texts 'A' and 'B' should be a little bit higher and more to the > left. The 'A' I want to align with the yaxis label of the left plot, > the 'B' with the values of the yaxis of the right plot. > > I hope my question is clear, I will appreciate any help! > > Thanks in advance, > > Hannes > > >  > > _______________________________________________ > Matplotlibusers mailing list > Matplotlibusers@... > https://lists.sourceforge.net/lists/listinfo/matplotlibusers > 
From: hettling <hettling@fe...>  20100519 12:31:12

Thanks for the suggestions, 'annotate' is what I need, I think. I get errors though, also when I run the example scripts from here: http://matplotlib.sourceforge.net/trunkdocs/users/annotations_guide.html#usingcomplexcoordinatewithannotation . I get the error 'NoneType' object is not iterable when I try plt.show() or try to save to eps. So I am not sure if I have the correct version of matplotlib installed. I checked out the newest matplotlib from the svn repository, removed my current installed version and installed the version in the 'trunk/' directory. 'annotate' did not work. Later, I installed matplotlib from the '/branches/v0_99_maint' directory. In both cases there were no errors in the installation, but still 'annotate' did not work. Could it be that I have the wrong library from the svn repository installed? Does r8319 mean release #8319? Kind Regards Hannes On Tue, 20100518 at 13:34 0400, JaeJoon Lee wrote: > This can be done relatively easily with the current svn version of > matplotlib (r8319). > Below is the modified version of your code. > > See > > http://matplotlib.sourceforge.net/trunkdocs/users/annotations_guide.html#usingcomplexcoordinatewithannotation > > for how the annotation works. > > While this is certainly possible with the released version, but it > will require you to write a few tens of lines of code. Basically, you > need create a custom Text class that update its position during the > drawing time. > > Regards, > > JJ > > ###Code > import scipy > import matplotlib.pyplot as plt > > fig = plt.figure() > ax = fig.add_subplot(121) > plt.plot(scipy.sin(scipy.arange(1,100, 0.001))) > plt.xlabel('xlabel') > yl = plt.ylabel("ylabel") > > plt.annotate("A", (0,1.), xycoords=(yl, "axes fraction"), > xytext=(0, 14), textcoords="offset points", > fontsize=14) > > ax = fig.add_subplot(122) > plt.plot(scipy.cos(scipy.arange(1,100, 0.001))) > plt.xlabel('xlabel') > > my_ticklabel = ax.get_yticklabels()[2] > # Note that there is no guarantee that all ticklabels are drawn. > plt.annotate("B", (0,1.), xycoords=(my_ticklabel, "axes fraction"), > xytext=(0, 14), textcoords="offset points", > fontsize=14) > > ###End Code > > > On Mon, May 17, 2010 at 11:08 AM, hettling <hettling@...> wrote: > > Dear all, > > > > I'm struggling with the following problem plotting my data: > > > > I have a figure with two panels next to each other, which I want to > > label 'A' and 'B'. I want to leftjustify my panel labels, but not to > > the box that contains the plot, but to the yaxis label. I played around > > with 'text()' and 'title()', but did not find a good solution except for > > giving the coordinates manually to 'text()'. This would be very > > inconvenient though, because I have many different plots on different > > scales. > > Here is what I tried: > > > > ###Code > > import scipy > > import matplotlib.pyplot as plt > > > > fig = plt.figure() > > ax = fig.add_subplot(121) > > plt.plot(scipy.sin(scipy.arange(1,100, 0.001))) > > plt.xlabel('xlabel') > > plt.ylabel("ylabel") > > plt.text(0,1,"A", fontsize=14, transform=ax.transAxes) > > > > ax = fig.add_subplot(122) > > plt.plot(scipy.cos(scipy.arange(1,100, 0.001))) > > plt.text(0,1,"B", fontsize=14, transform=ax.transAxes) > > plt.xlabel('xlabel') > > ###End Code > > > > So the texts 'A' and 'B' should be a little bit higher and more to the > > left. The 'A' I want to align with the yaxis label of the left plot, > > the 'B' with the values of the yaxis of the right plot. > > > > I hope my question is clear, I will appreciate any help! > > > > Thanks in advance, > > > > Hannes > > > > > >  > > > > _______________________________________________ > > Matplotlibusers mailing list > > Matplotlibusers@... > > https://lists.sourceforge.net/lists/listinfo/matplotlibusers > > 
Sign up for the SourceForge newsletter:
No, thanks