On Wed, Nov 9, 2011 at 10:20 AM, Howard <how...@renci.org> wrote:

>  On 11/9/11 11:13 AM, Joe Kington wrote:
>
> On Wed, Nov 9, 2011 at 10:07 AM, Howard <how...@renci.org> wrote:
>
>>  Hi all
>>
>> I'm a new user to matplotlib, and I'm having a little difficulty with
>> something I feel must be basic. When I plot our data, I'm using a canvas
>> that is 4"x4" at 128 DPI and saving the canvas as a png.  Here's the basics
>> of the code:
>>
>>    imageWidth = 4
>>    imageHeight = 4
>>    DPI = 128
>>
>>    figure1 = plt.figure(figsize=(imageWidth,imageHeight))
>>    plt.axis("off")
>>    plt.tricontourf(theTriangulation,
>>                    modelData,
>>                    theLookupTable.N,
>>                    cmap=theLookupTable)
>>    canvas = FigureCanvasAgg(figure1)
>>    canvas.print_figure(prefix + ".png", dpi=DPI)
>>
>> The png is 512x512 as I would expect, but the contoured image doesn't
>> fill the whole image.  How do I tell the library to map the plotted are to
>> the entire canvas and not leave a border around the rendered image?
>>
>
> You need to make an axis that fills up the entire figure.
>
> By default, axes don't fill up the entire figure to leave room for tick
> labels, axis lables, titles, etc.
>
> Try something like:
>
> import matplotlib as plt
>
> dpi = 128
> fig = plt.figure(figsize=(4,4))
>
> # Specifies an axis at 0, 0 with a width and height of 1 (the full width
> of the figure)
> ax = fig.add_axes([0,0,1,1])
>
> ax.tricontourf(...)
>
> fig.savefig('output.png', dpi=dpi)
>
>  Hope that helps,
> -Joe
>
> Hi Joe
>
> That did it!  Thanks much. Can I also turn off the tick marks on the new
> axis?
>
>
Sure! If you want an exact duplicate of your original code snippet, just
add an:

ax.axis('off')

or one of the many equivalent ways of hiding the entire axis.

If you'd rather keep the outline and white background patch, but just turn
the ticks off, then you can do something like:

for axis in [ax.xaxis, ax.yaxis]:
    ax.set_ticks([])

or similarly:

ax.tick_params(color='none')

Also, as you've probably already noticed, I meant to have "import
matplotlib.pyplot as plt" in my first reply, rather than "import matplotlib
as plt".

Cheers!
------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to