Plotting using Basemap and FigCanvasAgg with Matplotlib on a web server

Hi,

I’ve recently created a web application, using Django, to dynamically create maps from weather data. When I tried using FigCanvasAgg and figure.Figure, the image that was responded by the web server (using canvas.print_png and django.http.HttpResponse) did not show the map, just the scatter points. When I just saved the figure (that was created using a matplotlib.pyplot.figure() instance) in folder that is statically available on the web server, the image is perfect. There is an advantage to using the latter method as the saved images can be cached, but I’m curious as to why the FigCanvasAgg method doesn’t work.

Is this a known issue? If so, are there any workarounds?

Any help on this issue would be greatly appreciated.

Thanks,
Aman

You will need to post an example script.

···

On Aug 24, 2011, at 4:09 PM, Aman Thakral <aman.thakral@...287...> wrote:

Hi,

I've recently created a web application, using Django, to dynamically create maps from weather data. When I tried using FigCanvasAgg and figure.Figure, the image that was responded by the web server (using canvas.print_png and django.http.HttpResponse) did not show the map, just the scatter points. When I just saved the figure (that was created using a matplotlib.pyplot.figure() instance) in folder that is statically available on the web server, the image is perfect. There is an advantage to using the latter method as the saved images can be cached, but I'm curious as to why the FigCanvasAgg method doesn't work.

Is this a known issue? If so, are there any workarounds?

Any help on this issue would be greatly appreciated.

Sorry about that. I’ve attached a sample script.
-Aman

views.py (1.97 KB)

···

On Wed, Aug 24, 2011 at 9:05 PM, John Hunter <jdh2358@…287…> wrote:

On Aug 24, 2011, at 4:09 PM, Aman Thakral <aman.thakral@…287…> wrote:

Hi,

I’ve recently created a web application, using Django, to dynamically create maps from weather data. When I tried using FigCanvasAgg and figure.Figure, the image that was responded by the web server (using canvas.print_png and django.http.HttpResponse) did not show the map, just the scatter points. When I just saved the figure (that was created using a matplotlib.pyplot.figure() instance) in folder that is statically available on the web server, the image is perfect. There is an advantage to using the latter method as the saved images can be cached, but I’m curious as to why the FigCanvasAgg method doesn’t work.

Is this a known issue? If so, are there any workarounds?

Any help on this issue would be greatly appreciated.

You will need to post an example script.

OK, so it seems to be working if I use fig=plt.figure() instead of fig = Figure() but I’m not sure why this is the case.

-Aman

···

On Thu, Aug 25, 2011 at 10:50 AM, Aman Thakral <aman.thakral@…287…> wrote:

Sorry about that. I’ve attached a sample script.
-Aman

On Wed, Aug 24, 2011 at 9:05 PM, John Hunter <jdh2358@…287…> wrote:

On Aug 24, 2011, at 4:09 PM, Aman Thakral <aman.thakral@…287…> wrote:

Hi,

I’ve recently created a web application, using Django, to dynamically create maps from weather data. When I tried using FigCanvasAgg and figure.Figure, the image that was responded by the web server (using canvas.print_png and django.http.HttpResponse) did not show the map, just the scatter points. When I just saved the figure (that was created using a matplotlib.pyplot.figure() instance) in folder that is statically available on the web server, the image is perfect. There is an advantage to using the latter method as the saved images can be cached, but I’m curious as to why the FigCanvasAgg method doesn’t work.

Is this a known issue? If so, are there any workarounds?

Any help on this issue would be greatly appreciated.

You will need to post an example script.