Clip text in bars

I'm trying to set up a chart that shows a runtime trace of a single frame.
Most of it is straight forward, however one aspect of it is driving me
crazy. I would like to label the inside of the bar fragments (each represent
a function call with the x-extent being its runtime) with the name of the
task, however I would like the text itself to be fully contained within the
bar itself. I should, in theory, be able to set the clipping box of the text
to be the bounding box of the bar and that should give me the result I want.
Except, I'm not getting that.

Any ideas?

See the code below:

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)
rect = ax.barh(10, 50, 3, facecolor='green', visible=True)
ax.set_ylim(0,35)
ax.set_xlim(0,1000)

text0 = ax.text(0,11,'JobName',clip_on=True,clip_box=rect[0].get_bbox())

ax.grid(True)

plt.show()

···

--
View this message in context: http://old.nabble.com/Clip-text-in-bars-tp28693489p28693489.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

The bbox needs to be in a proper coordinate.

from matplotlib.transforms import TransformedBbox
bb = TransformedBbox(rect[0].get_bbox(), ax.transData)

Also, do not use clip_on when clip_box is used. clip_on override
clip_box with ax.bbox.

text0 = ax.text(0,11,'JobName', clip_box=bb)

A complete code is attached.

Regards,

-JJ

import matplotlib.pyplot as plt
from matplotlib.transforms import TransformedBbox

fig = plt.figure()

ax = fig.add_subplot(111)
rect = ax.barh(10, 50, 3, facecolor='green', visible=True)
ax.set_ylim(0,35)
ax.set_xlim(0,1000)

bb = TransformedBbox(rect[0].get_bbox(), ax.transData)

text0 = ax.text(0,11,'JobName', clip_box=bb)

ax.grid(True)

plt.show()

···

On Thu, May 27, 2010 at 8:41 AM, wrpd_mnd <wrpd_mnd@...9...> wrote:

I'm trying to set up a chart that shows a runtime trace of a single frame.
Most of it is straight forward, however one aspect of it is driving me
crazy. I would like to label the inside of the bar fragments (each represent
a function call with the x-extent being its runtime) with the name of the
task, however I would like the text itself to be fully contained within the
bar itself. I should, in theory, be able to set the clipping box of the text
to be the bounding box of the bar and that should give me the result I want.
Except, I'm not getting that.

Any ideas?

See the code below:

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)
rect = ax.barh(10, 50, 3, facecolor='green', visible=True)
ax.set_ylim(0,35)
ax.set_xlim(0,1000)

text0 = ax.text(0,11,'JobName',clip_on=True,clip_box=rect[0].get_bbox())

ax.grid(True)

plt.show()

--
View this message in context: http://old.nabble.com/Clip-text-in-bars-tp28693489p28693489.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Ah, thanks a lot.

···

--- On Thu, 5/27/10, Jae-Joon Lee <lee.j.joon@...287...> wrote:

From: Jae-Joon Lee <lee.j.joon@...287...>
Subject: Re: [Matplotlib-users] Clip text in bars
To: "wrpd_mnd" <wrpd_mnd@...9...>
Cc: matplotlib-users@lists.sourceforge.net
Date: Thursday, May 27, 2010, 9:24 AM
The bbox needs to be in a proper
coordinate.

from matplotlib.transforms import TransformedBbox
bb = TransformedBbox(rect[0].get_bbox(), ax.transData)

Also, do not use clip_on when clip_box is used. clip_on
override
clip_box with ax.bbox.

text0 = ax.text(0,11,'JobName', clip_box=bb)

A complete code is attached.

Regards,

-JJ

import matplotlib.pyplot as plt
from matplotlib.transforms import TransformedBbox

fig = plt.figure()

ax = fig.add_subplot(111)
rect = ax.barh(10, 50, 3, facecolor='green', visible=True)
ax.set_ylim(0,35)
ax.set_xlim(0,1000)

bb = TransformedBbox(rect[0].get_bbox(), ax.transData)

text0 = ax.text(0,11,'JobName', clip_box=bb)

ax.grid(True)

plt.show()

On Thu, May 27, 2010 at 8:41 AM, wrpd_mnd <wrpd_mnd@...9...> > wrote:
>
> I'm trying to set up a chart that shows a runtime
trace of a single frame.
> Most of it is straight forward, however one aspect of
it is driving me
> crazy. I would like to label the inside of the bar
fragments (each represent
> a function call with the x-extent being its runtime)
with the name of the
> task, however I would like the text itself to be fully
contained within the
> bar itself. I should, in theory, be able to set the
clipping box of the text
> to be the bounding box of the bar and that should give
me the result I want.
> Except, I'm not getting that.
>
> Any ideas?
>
> See the code below:
>
> import numpy as np
> import matplotlib.pyplot as plt
>
> fig = plt.figure()
> ax = fig.add_subplot(111)
> rect = ax.barh(10, 50, 3, facecolor='green',
visible=True)
> ax.set_ylim(0,35)
> ax.set_xlim(0,1000)
>
> text0 =
ax.text(0,11,'JobName',clip_on=True,clip_box=rect[0].get_bbox())
>
> ax.grid(True)
>
> plt.show()
>
> --
> View this message in context: http://old.nabble.com/Clip-text-in-bars-tp28693489p28693489.html
> Sent from the matplotlib - users mailing list archive
at Nabble.com.
>
>
>
------------------------------------------------------------------------------
>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> matplotlib-users List Signup and Options
>