Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo
Close
From: Dani Marti <daniel.marti@up...>  20060828 18:28:40

Hi all, I'd like to plot a diagram that contains different graphs. Since the diagram has to help visually the reader, it is important to add symbols and visual guides that show the relations between the different graphs. A typical example would be a diagram consisting of three graphs (let's call them A, B, C), which correspond to the same given function for three different parameters. Apart from the graphs, the diagram would contains arrows that indicate the direction of increasing values of the parameter: A > B > C > (the example is silly, but I hope the idea is clear). For me the most natural way to proceed would be to generate separately the three plots, without specifying their absolute position in the canvas, and afterwards stroke them as mere objects. It would be in this last step where I would specify the positions. The pseudocode would look like: A = generate_graph(parameter=0) B = generate_graph(parameter=1) C = generate_graph(parameter=2) Draw A at position x1 in the canvas Draw B at position x2 in the canvas Draw C at position x3 in the canvas Draw an arrow between A and B Draw an arrow between B and C Draw a long arrow below the row of graphs How would you code this in PyX? To not stick to this particular example (I apologize for being so reiterative) I am asking about how to draw a general diagram like http://pyx.sourceforge.net/gallery/misc/connect.html but with graphs instad of boxed letters. I guess PyX is indeed treating graphs as objects that are eventually stroked in a canvas, but I don't know how to effectively do what I want. Thanks a lot for your patience and attention, d 
From: Michael J Gruber <michaeljgruber+<pyx@fa...>  20060829 09:06:09

Dani Marti venit, vidit, dixit 20060828 20:28: > Hi all, > > I'd like to plot a diagram that contains different graphs. Since the > diagram has to help visually the reader, it is important to add symbols > and visual guides that show the relations between the different graphs. > A typical example would be a diagram consisting of three graphs (let's > call them A, B, C), which correspond to the same given function for > three different parameters. Apart from the graphs, the diagram would > contains arrows that indicate the direction of increasing values of the > parameter: > > A > B > C > > > > (the example is silly, but I hope the idea is clear). > > For me the most natural way to proceed would be to generate separately > the three plots, without specifying their absolute position in the > canvas, and afterwards stroke them as mere objects. It would be in this > last step where I would specify the positions. The pseudocode would > look like: > > A = generate_graph(parameter=0) > B = generate_graph(parameter=1) > C = generate_graph(parameter=2) > > Draw A at position x1 in the canvas > Draw B at position x2 in the canvas > Draw C at position x3 in the canvas > > Draw an arrow between A and B > Draw an arrow between B and C > Draw a long arrow below the row of graphs Perfect. > How would you code this in PyX? > > To not stick to this particular example (I apologize for being so > reiterative) I am asking about how to draw a general diagram like > http://pyx.sourceforge.net/gallery/misc/connect.html > but with graphs instad of boxed letters. > > I guess PyX is indeed treating graphs as objects that are eventually > stroked in a canvas, but I don't know how to effectively do what I want. Yes, you explained very well how to do it ;) Confirming your guess: A graph is a canvas in the same way as the text boxes A, B, C, D in the "connect" example are canvasses. [ OK, they are special canvasses, but all are canvasses). So, once you've generated your graphs A, B, C you can treat them in the same way as that example treats the text boxes: drawing boxes and backgrounds if you like, inserting them into another canvas, drawing connectors. As for the positioning: graph.graphxy() accepts parameters xpos and ypos just like the first two parameters of text.text() (or translate the graph canvasses). Cheers, Michael 
From: Dani Marti <daniel.marti@up...>  20060829 13:44:29

Thank you Michael for your answer. I'm glad I was pointing to the good direction. The concept is now clear to me, but I don't know how to implement it. From my previous example A = generate_graph(0), My question is, what precise object should the function "generate_graph" return? Is there anything wrong in def generate_graph(parameter): g = graph.graphxy(width=1, height=1) g.plot(graph.data.function("y(x)= x**4  %f * x**2" % parameter, min=2, max=2)) return g A = generate_graph(1) ? [There are no errors, but I wonder if this the proper way to do it] > As for the positioning: graph.graphxy() accepts parameters xpos and > ypos just like the first two parameters of text.text() (or translate > the graph canvasses). That's precisely what I prefer not to do: to specify the position at the very beginning, through the 'graph.graphxy' call inside 'generate_graph'. This would require to modify the function 'generate_graph' to add a second argument (the position), which I don't want to do. My idea is to create the 'floating' figure (using Gimp terminology) and then 'anchor' it at the position I choose at the end. Is that possible? Thanks a lot for your answer. d 
From: Joerg Lehmann <joergl@us...>  20060829 13:49:34

Hello Dani, On 29.08.06, Dani Marti wrote: > Thank you Michael for your answer. I'm glad I was pointing to the good > direction. The concept is now clear to me, but I don't know how to > implement it. From my previous example > > A = generate_graph(0), > > My question is, what precise object should the function "generate_graph" > return? > > Is there anything wrong in > > def generate_graph(parameter): > g = graph.graphxy(width=1, height=1) > g.plot(graph.data.function("y(x)= x**4  %f * x**2" % parameter, min=2, max=2)) > return g > > A = generate_graph(1) That's perfect. > > As for the positioning: graph.graphxy() accepts parameters xpos and > > ypos just like the first two parameters of text.text() (or translate > > the graph canvasses). > That's precisely what I prefer not to do: to specify the position at the > very beginning, through the 'graph.graphxy' call inside 'generate_graph'. > This would require to modify the function 'generate_graph' to add a > second argument (the position), which I don't want to do. My idea is to > create the 'floating' figure (using Gimp terminology) and then 'anchor' > it at the position I choose at the end. Is that possible? Just do something like c.insert(A, [trafo.translate(xpos, ypos)]) where c is a canvas and xpos and ypos are the desired positions of the graph. HTH, Jörg 
From: Michael J Gruber <michaeljgruber+<pyx@fa...>  20060829 13:52:59

Dani Marti venit, vidit, dixit 20060829 15:44: > Thank you Michael for your answer. I'm glad I was pointing to the good > direction. The concept is now clear to me, but I don't know how to > implement it. From my previous example > > A = generate_graph(0), > > My question is, what precise object should the function "generate_graph" > return? > > Is there anything wrong in > > def generate_graph(parameter): > g = graph.graphxy(width=1, height=1) > g.plot(graph.data.function("y(x)= x**4  %f * x**2" % parameter, min=2, max=2)) > return g > > A = generate_graph(1) > ? > > [There are no errors, but I wonder if this the proper way to do it] Yes, this is exactly what I meant. graph.graphxy returns a canvas. >> As for the positioning: graph.graphxy() accepts parameters xpos and >> ypos just like the first two parameters of text.text() (or translate >> the graph canvasses). > That's precisely what I prefer not to do: to specify the position at the > very beginning, through the 'graph.graphxy' call inside 'generate_graph'. > This would require to modify the function 'generate_graph' to add a > second argument (the position), which I don't want to do. My idea is to > create the 'floating' figure (using Gimp terminology) and then 'anchor' > it at the position I choose at the end. Is that possible? Yes, that's what I meant by "translate canvas". Sorry for being so concise... Uh, Joerg was faster, he just sent you the translate code ;) Happy PyXing! Michael 