Python Matplotlib : Just the graph image

Question:

I cannot get pyplot to produce “cropped” images, that is, get rid of the grey left and right borders, as it is, it is not an accurate representation of the sound waveform : This sound file has no silence before and after.

enter image description here

My code :

import gtk

from matplotlib.figure import Figure
from numpy import arange, sin, pi
import scipy.io.wavfile as wavfile

from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas

    win = gtk.Window()
    win.connect("destroy", lambda x: gtk.main_quit())
    win.set_default_size(400,300)
    win.set_title("Cropping figure")

    rate, data = wavfile.read(open('/home/px/gare_du_nord-catchlak.wav', 'r'))
    f = Figure()
    a = f.add_subplot(111, axisbg=(0.1843, 0.3098, 0.3098))
    a.plot(range(len(data)),data, color="OrangeRed",  linewidth=0.5, linestyle="-")
    a.axis('off')
    a.autoscale_view('tight')
    canvas = FigureCanvas(f)  # a gtk.DrawingArea

    win.add(canvas)

    win.show_all()
    gtk.main()
Asked By: yPhil

||

Answers:

OK, I got my answer :

f.subplots_adjust(0, 0, 1, 1)

EDIT:

This also works, in fact it works even better:

a.margins(0, 0)
Answered By: yPhil
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.