Hi,
I've searched the archives but can't find a solution to this problem.
I'd like to remove the whitespace, padding, offset, etc on the left and
right of the plot as I'm writing the entire thing to a jpg. I've turned
the frame, axes, ticks off, but the space still remains.
I've attached the code and the resulting image.
code (inside a django app):
def hours_chart(request):
from PIL import Image as PILImage
from matplotlib.backends.backend_agg import FigureCanvasAgg as
FigureCanvas
from matplotlib.figure import Figure
from matplotlib.axes import Axes
from StringIO import StringIO
fig = Figure(figsize=(3,1),facecolor='r') # w,h in inches
fig.frameon = False
canvas = FigureCanvas(fig)
ax = fig.add_subplot(111)
values = [d.get_total_hours() for d in
Debrief.objects.all().order_by('date')] # the data
ax.plot(values,lw=2)
ax.axis('off')
canvas.draw()
size = canvas.get_renderer().get_canvas_width_height()
buf=canvas.tostring_rgb()
im=PILImage.fromstring('RGB', size, buf, 'raw', 'RGB', 0, 1)
imdata=StringIO()
im.save(imdata, format='JPEG')
response = HttpResponse(imdata.getvalue(), mimetype='image/jpeg')
return response
This is the result -- as you can see there's a lot of white space on the
left of the plot: