Thank you very much for your help Massimo.
The problem I have is not how to plot easily in matplotlib. My problem is 
how to display
in my web2py view the NetworkX drawing made using nx.draw without saving 
the png file in disk 
but using some code like:

canvas=FigureCanvas(fig)
    stream=cStringIO.StringIO()
    canvas.print_png(stream)
    return stream.getvalue()

as I have seen in the web2py Application Development Cookbook and in your 
paper "web2py for Scientific Applications" (2011). 

If you try for example:

import matplotlib.pyplot as plt
import networkx as nx
G = nx.path_graph(21)
nx.draw(G)
plt.show()

you get a plot. Now, how should I put this code in my model or controller 
to get 
the plot in my web2py view. 

Thank you for your help.






 

On Sunday, April 13, 2014 5:59:39 PM UTC+2, Massimo Di Pierro wrote:
>
> Not sure but look into https://github.com/mdipierro/canvas
>
> On Saturday, 12 April 2014 04:10:42 UTC-5, Luis Fontes wrote:
>>
>> I am trying to plot a graph using NetworkX draw function but 
>> using cStringIO.StringIO(). I have read
>> how to do it in web2py Application Development Cookbook.
>>
>> Let's say I have something like:
>>
>> import matplotlib.pyplot as plt
>> import networkx as nx
>>
>> G = nx.path_graph(8)
>> nx.draw(G)
>> plt.show()
>>
>> This code plots and shows the graph. Now, to place it in a web2py view I 
>> should use a function like:
>>
>>
>> def mygraph()
>>     fig=Figure()
>>
>>     .....
>>     .....
>>     .....
>>
>>     canvas=FigureCanvas(fig)
>>     stream=cStringIO.StringIO()
>>     canvas.print_png(stream)
>>     return stream.getvalue()
>>
>> The problem is how to place the plot generated by nx.path_graph(8) and 
>> nx.draw(G) in the code in
>> blue in order to make it work.
>>
>> I am learning web2py and I am nor expert in NetworkX or matplotlib 
>> packages. Sorry if my question
>> is stupid.
>>
>> Thank you.
>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to