Python script Graph to webpage

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Python script Graph to webpage

ihaag
Hi all,

I am going to attempt to move my current python script (most seen here:http://stackoverflow.com/questions/41697966/python-pie-chart-not-presented-in-order
To a web application so every time the page is refreshed the python script will run and display the latest graph & pie chart.

Would anyone have any examples I could follow to get some idea of how I could create something like this? 

Thanks
TJ


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Python script Graph to webpage

Paul Hobson-2
TJ,

There's an example of embedding matplotlib using the webagg backend in the official documentation here:

I don't have much experience with it, but I hope it helps.
-p

On Tue, Jan 24, 2017 at 11:00 PM, Trevor H <[hidden email]> wrote:
Hi all,

I am going to attempt to move my current python script (most seen here:http://stackoverflow.com/questions/41697966/python-pie-chart-not-presented-in-order
To a web application so every time the page is refreshed the python script will run and display the latest graph & pie chart.

Would anyone have any examples I could follow to get some idea of how I could create something like this? 

Thanks
TJ


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users



_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Python script Graph to webpage

tcaswell

You can also do this via one of the web frame works (ex flask, django,...) and just serve the png.  The webbackend will provide an interactive figure.

Something like: https://gist.github.com/wilsaj/862153 (py3 version attached).

Documenting how to use mpl within the web-frameworks is something that should definitely be in the main docs.

Tom

On Wed, Jan 25, 2017, 11:39 Paul Hobson <[hidden email]> wrote:
TJ,

There's an example of embedding matplotlib using the webagg backend in the official documentation here:

I don't have much experience with it, but I hope it helps.
-p

On Tue, Jan 24, 2017 at 11:00 PM, Trevor H <[hidden email]> wrote:
Hi all,

I am going to attempt to move my current python script (most seen here:http://stackoverflow.com/questions/41697966/python-pie-chart-not-presented-in-order
To a web application so every time the page is refreshed the python script will run and display the latest graph & pie chart.

Would anyone have any examples I could follow to get some idea of how I could create something like this? 

Thanks
TJ


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Python script Graph to webpage

Glenn Nelson
In reply to this post by ihaag
Here's my brief outline of a really basic approach.
You will create a simple program, let's call it myplot.py.

import sys
import matplotlib
matplotlib.use('Agg')       # backend that is used for web graphics
import matplotlib.pyplot as plt
# create your plot here, using 'plt'
print 'Content-Type: image/png\n'
plt.savefig( sys.stdout, format='png' )

And then in your web page, you have HTML IMG tag with SRC="<website>/myplot.py"

That's all there is to it. When I first got into this, I don't think the suggested webagg backend was available to me.
Web browsers will normally cache the image, so you probably want to set expiration headers, either Cache-Control or Expires.
Another way to force browser to make a new request is to add a parameter with random value:
SRC="<website>/myplot.py?x=<random number>"
This would be especially helpful in testing, because the browser would never think it had already cached the image (unless the random number repeats).


----
Glenn Nelson in Santa Cruz

On Tue, Jan 24, 2017 at 11:00 PM, Trevor H <[hidden email]> wrote:
Hi all,

I am going to attempt to move my current python script (most seen here:http://stackoverflow.com/questions/41697966/python-pie-chart-not-presented-in-order
To a web application so every time the page is refreshed the python script will run and display the latest graph & pie chart.

Would anyone have any examples I could follow to get some idea of how I could create something like this? 

Thanks
TJ


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users



_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users