1

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()

1 Answer 1

3

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)
Sign up to request clarification or add additional context in comments.

1 Comment

I cannot do that before 2 days

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.