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_...@yahoo.com> 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 > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ------------------------------------------------------------------------------ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users