2

I do I plot a "continuous", moving plot in Pygame, like the plot in this "NetLogo" simulation? My main difficulty is not the plotting itself (lines between points) but the process of moving the framework of the plot when the curve getting close to the edge of the box.

Thank you.

4
  • the link does not work - class not found Commented Mar 10, 2013 at 18:42
  • Press "run altruism" here: ccl.northwestern.edu/netlogo/models/Altruism Commented Mar 10, 2013 at 18:58
  • ok, could you explain a bit more, what you are trying to accomplish? To operate on pixels you can use pxarray Commented Mar 10, 2013 at 20:10
  • I made a simulation similar to this simulation. I want to implement in Pygame a plot that is similar to the plot in NetLogo's simulation (in the left down corner), a plot that is updated continuously while the simulation is running. Commented Mar 10, 2013 at 20:16

1 Answer 1

1

Ok, so you can make a plot similar to the one in the application in the following way:

create a surface of the size of the graph. Then create a pixel array, so you will be able to modify the graph.

pxarray = pygame.PixelArray (surface)

you can then manipulate the array like any other array:

pxarray[x][y] = 0xFF00FF # this will set pixel at x,y to purple

you can normally then normally blit the surface to the screen.

more on pixel arrays : http://www.pygame.org/docs/ref/pixelarray.html

EDIT: Using pxarray, and transform you will have a shrinking graph if your numbers go out of range. Simply when the point is too big for the plot, you add enough rows, and use transform.scale to scale back to the original resolution.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you but constructing the graph itself is not my difficulty. Notice what happen in the simulation when the curve getting close to the edge of the graph: the all curve "shrinks" in a way that the new data can be displayed, although the curve is getting close to the edge. How do i mimic this behavior?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.