On Saturday, July 23, 2011, robert rottermann <rob...@redcor.ch> wrote:
> Hi there,
>
> I am creating an image with mathplotlib. This image is then shown an a web
page.
> now ma question.
> the Image is set in a large gray area. I assume it is the space needed for
the
> axis which I do not show.
> How can I suppress this gray background?
>
> thanks
> robert
>
> here the code I use to create the image:
>     def makeHlwdChart(self, values = ['a', 'd', 'e', 'f', 'b']):
>         # the need for following two lines I learned by appling voodoo and
pdb
>         img_resource =
> self.context.restrictedTraverse('++resource++effizienz_balken_01.jpg')
>         imp_path = img_resource.context.path
>         pic = plt.imread(imp_path)
>         # the picture is upside down so rotate and fip it
>         pic = np.fliplr(np.rot90(pic, k=2))
>         # draw it on the canvas
>         plt.imshow(pic)
>         frame1 = plt.gca()
>         # hide axes
>         frame1.axes.get_xaxis().set_visible(False)
>         frame1.axes.get_yaxis().set_visible(False)
>         #frame1.subplots_adjust(left=0)
>
>         # generate the colored markers that denot the value
>         # write a label so, that it is within the marker
>         funs = [th, ge, hh, en, pr]
>         font0 = FontProperties()
>         font = font0.copy()
>         font.set_weight('bold')
>         for i in range(len(values)):
>             # add the colord marker
>             frame1.add_patch(funs[i](values[i], True))
>             # get postition of the label
>             p = funs[i](values[i], offset=TEXTOFFSET)
>             # write the label
>             frame1.text(p[0], p[1], values[i].upper(),
fontproperties=font)
>
>         return pic
>

When you call savefig(), you can pass it the kwarg option of
bbox_inches='tight' and that should help get rid of any extra area you may
have.

Ben Root
------------------------------------------------------------------------------
Storage Efficiency Calculator
This modeling tool is based on patent-pending intellectual property that
has been used successfully in hundreds of IBM storage optimization engage-
ments, worldwide.  Store less, Store more with what you own, Move data to 
the right place. Try It Now! http://www.accelacomm.com/jaw/sfnl/114/51427378/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to