Return images with matplotlib?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jan Danielsson

    #1

    Return images with matplotlib?

    Hello all,

    I have written a program which takes some data from a postgresql
    database, and via mod_python outputs it as tables on a web site. Now I
    would like to present these tables as graphs, which matplotlib can do.
    But in order to properly display these graphs on the web page, I need
    to return the image data, like so:

    def barchart(req, params):
    some_format = matplotlib.gene rate_fancy_grap h(params)
    png_buf = make_png_buffer (some_format)
    return png_buf

    Is this possible? If so -- how?

    --
    Kind regards,
    Jan Danielsson
    ------------ And now a word from our sponsor ------------------
    For a quality usenet news server, try DNEWS, easy to install,
    fast, efficient and reliable. For home servers or carrier class
    installations with millions of users it will allow you to grow!
    ---- See http://netwinsite.com/sponsor/sponsor_dnews.htm ----
  • Istvan Albert

    #2
    Re: Return images with matplotlib?

    On Feb 4, 8:18 pm, Jan Danielsson <jan.m.daniels. ..@gmail.comwro te:
    def barchart(req, params):
    some_format = matplotlib.gene rate_fancy_grap h(params)
    png_buf = make_png_buffer (some_format)
    return png_buf
    >
    Is this possible? If so -- how?
    savefig does that. You can save to a file name or a buffer.



    i.


    Comment

    • Joshua J. Kugler

      #3
      Re: Return images with matplotlib?

      Jan Danielsson wrote:
      Hello all,
      >
      I have written a program which takes some data from a postgresql
      database, and via mod_python outputs it as tables on a web site. Now I
      would like to present these tables as graphs, which matplotlib can do.
      But in order to properly display these graphs on the web page, I need
      to return the image data, like so:
      >
      def barchart(req, params):
      some_format = matplotlib.gene rate_fancy_grap h(params)
      png_buf = make_png_buffer (some_format)
      return png_buf
      >
      Is this possible? If so -- how?
      If you are returning the buffer (and nothing else) directly to a browser you
      can't print a Content-type header that says it's a png file, and the
      browser will accept it as a graphic, as long as you call the script from
      within an IMG tag.

      j

      --
      Joshua Kugler
      Lead System Admin -- Senior Programmer

      PGP Key: http://pgp.mit.edu/  ID 0xDB26D7CE

      --
      Posted via a free Usenet account from http://www.teranews.com

      Comment

      Working...