Thank you very much Massimo. I will check if NetworkX can draw graphs 
without pyplot. Othercase
I will have to draw my graphs from scratch using Figure, Axis, etc.


On Monday, April 14, 2014 3:28:43 PM UTC+2, Massimo Di Pierro wrote:
>
> matplotlib has two API. A stateless and a statefull.
>
> The statefull mode is called matplotlib.pyplot and is it designed for 
> some compatibility with Matlab. Most of the examples posted are with 
> pyplot. The problem is that pyplot does not work for multithreaded web apps 
> because the state is in a global object instead of a local variable.
>
> You need to convert your example so that it does not use pyplot.
>
> I am not sure how to do it in your case but look how Canvas handles 
> Figure, Axis, and Plots without pyplot.
>
> Massimo
>
>
>
>
> On Sunday, 13 April 2014 12:32:05 UTC-5, Luis Fontes wrote:
>>
>> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to