text element just above previous text element

I like to have 2 or 3 text elements "stacked" on top of each other on top of a bar.

Currently it works for the first text element by doing:

height = bar.get_height()
xCorr = bar.get_x()
yCorr = 0.20 + height

txtax = axes.text(xCorr, yCorr, hstr)

trying to add the second text just above the previous one I tried this:

pCorr = yCorr + txtax.get_size() + 0.4
txtax = axes.text(xCorr, pCorr, hstrPerc)

It looks like my problem is that get_x() returns a value in ticks and txtax.get_size() is in pixels and I can't find a way to get at the height of the text element in ticks.

Can anyone please push me in the right direction.

Werner

I like to have 2 or 3 text elements "stacked" on top of each other on
top of a bar.

Currently it works for the first text element by doing:

height = bar.get_height()
xCorr = bar.get_x()
yCorr = 0.20 + height

txtax = axes.text(xCorr, yCorr, hstr)

trying to add the second text just above the previous one I tried this:

pCorr = yCorr + txtax.get_size() + 0.4
txtax = axes.text(xCorr, pCorr, hstrPerc)

I recommend you to use "annotate".

http://matplotlib.sourceforge.net/api/pyplot_api.html?highlight=annotate#matplotlib.pyplot.annotate

you may begin with something like below.

txt=plt.text(0.5, 0.5, "Test1")
plt.annotate("My Test2",
             xy=(0.5, 1.), xycoords=txt,
             xytext=(0, 5), textcoords="offset points",
             ha="center", va="bottom")

See belows for more details.

http://matplotlib.sourceforge.net/users/annotations_guide.html#using-complex-coordinate-with-annotation

http://matplotlib.sourceforge.net/users/annotations_guide.html#using-complex-coordinate-with-annotation

-JJ

···

On Tue, Nov 9, 2010 at 12:21 AM, Werner F. Bruhin <werner.bruhin@...185...> wrote:

It looks like my problem is that get_x() returns a value in ticks and
txtax.get_size() is in pixels and I can't find a way to get at the
height of the text element in ticks.

Can anyone please push me in the right direction.

Werner

------------------------------------------------------------------------------
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a
Billion" shares his insights and actions to help propel your
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Finally figured it out after pulling some hear.

Using "axes.annotate" instead of "axes.text" worked for me, i.e. something like this:

axes.annotate(hstr, xy=(xCorr, yCorr), xytext=(0, 5), textcoords='offset points')

instead of what I did originally.

Werner

···

On 08/11/2010 16:21, Werner F. Bruhin wrote:

I like to have 2 or 3 text elements "stacked" on top of each other on
top of a bar.

Currently it works for the first text element by doing:

height = bar.get_height()
xCorr = bar.get_x()
yCorr = 0.20 + height

txtax = axes.text(xCorr, yCorr, hstr)

trying to add the second text just above the previous one I tried this:

pCorr = yCorr + txtax.get_size() + 0.4
txtax = axes.text(xCorr, pCorr, hstrPerc)

It looks like my problem is that get_x() returns a value in ticks and
txtax.get_size() is in pixels and I can't find a way to get at the
height of the text element in ticks.

Can anyone please push me in the right direction.

Werner

------------------------------------------------------------------------------
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a
Billion" shares his insights and actions to help propel your
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options