images for web sites

Hi,

I am trying to make plots by using matplotlib.pyplot (within a Python
script) to be used in a web site (apache, and PHP). I am using Ubuntu
12.04.3. The script works fine when run from the command line (it is able to
generate the image with "savefig"), but when the script doesn't work when
run from PHP under an apache request. I have found a similar problem in this
post:
http://matplotlib.1069221.n5.nabble.com/savefig-fails-under-apache-on-solaris-td15122.html

Finally, I have found the solution in this web:
http://texnological.blogspot.com.es/2013/01/how-to-execute-python-matplolib-pylab.html

The solution consists on importing matplotlib in this way:
  # To import pylab
  os.environ[ 'MPLCONFIGDIR' ] = '/tmp/'
  import matplotlib
  matplotlib.use('agg')
  import pylab

This works for me, but I don't know whether this is a bug and it has to be
reported anywhere. The best option should be to import it in a regular way
(such as import matplotlib.pyplot as plt), and this can be confusing for a
lot of people. Well, let me know. Thank you.

Best regards,

Jilguero.

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/images-for-web-sites-tp42581.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Check out http://matplotlib.org/faq/howto_faq.html#matplotlib-in-a-web-application-server

Cheers,
Scott

···

On 3 December 2013 14:50, jilguero <jilguero888@...287...> wrote:

I am trying to make plots by using matplotlib.pyplot (within a Python
script) to be used in a web site (apache, and PHP). I am using Ubuntu
12.04.3. The script works fine when run from the command line (it is able to
generate the image with "savefig"), but when the script doesn't work when
run from PHP under an apache request. I have found a similar problem in this
post:
http://matplotlib.1069221.n5.nabble.com/savefig-fails-under-apache-on-solaris-td15122.html

Finally, I have found the solution in this web:
http://texnological.blogspot.com.es/2013/01/how-to-execute-python-matplolib-pylab.html

The solution consists on importing matplotlib in this way:
  # To import pylab
  os.environ[ 'MPLCONFIGDIR' ] = '/tmp/'
  import matplotlib
  matplotlib.use('agg')
  import pylab

This works for me, but I don't know whether this is a bug and it has to be
reported anywhere. The best option should be to import it in a regular way
(such as import matplotlib.pyplot as plt), and this can be confusing for a
lot of people. Well, let me know. Thank you.

Hi Scott,

Ok!. Thank you. I take note.

Best regards,

Jilguero.

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/images-for-web-sites-tp42581p42604.html
Sent from the matplotlib - users mailing list archive at Nabble.com.