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.
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.
Related
I am currently working on a 3D simulation data. I have a 3D surface, for simplicity, lets say, I have a hemispherical surface. So naturally, I have all the (x,y,z) coordinates that make up the surface. Now I also have a fourth array having the values of some variable (say Pressure for example) at all the (x,y,z) locations that make up the hemispherical surface. My aim is to plot the hemispherical surface and the surface should be coloured according to the fourth array (i.e according to the value of Pressure at that surface).
I have tried pyplot.scatter function from matplotlib, where i use pyplot.scatter(x,y,z, c= Pressure_array) but it leaves me with an artefact like the one shown below (image shows a zoomed in portion of the entire plot)
Notice the fringe like circular pattern. This arises because a Cartesian grid is sampled by a spherical surface and the same is plotted by the scatter points. This pattern remains even upon interpolation of the color values
I am looking for an alternative to the scatter plot method where the surface will be smoother and the circular fringes will be absent. I am aware that matplotlib has surface plots, but i am unable to use it because there, the 'z' coordinate sets both, the height of the plot in 3D and essentially the Color of the surface as well.
Any alternative to scatter plot or surface plot, or a way to get the same domne with the surface plot function in matplotlib will be much appreciated.
I'm using Python, and I have some data which can be projected on to points within an equilateral triangle whose side lengths sum to 1.
I'm not sure if there is an easy way to visualise a plot like this from Matplotlib or similar libraries, or if I'm just going to have to use a drawing package from scratch to make it happen. Any pointers gratefully recieved. Thanks!
If all you want to do is plot a few dots on a graph, you can infact use Matfplotlib's scatter plots for this:
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.scatter.html
Using plt.xlim(*min*, *max*) and plt.ylim(*min*, *max*), you can set the limits of the graph manually to fit your values (might not be neccessary though).
You can draw lines on the graph for the triangle shape (if you need that): How to draw a line with matplotlib?
If you don't need a scale, you can even remove that to have a blank canvas: Matplotlib plots: removing axis, legends and white spaces
Well, the problem I have is the following one.
I have data for axis X, Y and Z, and I want to plot the surface. For that I first interpolate/extrapolate to get , more mesh points and then I plot the surface (in Python) with plot_surface() function and I get it.
Later I have to use those points that I have for the mesh (already interpolated) as input in another function. As output I want the new surface and get it. But how can I get the coordinates of every point of that surface? As if I pointed with the cursor at that point.
I have to interpolate again?
Or there is other way?
Please see below image:
I set the figure size of plt equal to something like (4,6) and set axis to off and margin to zero.
Then continue to draw polyline using coordinate array by ax.plot(line[:,1],line[:,0])
after this I don’t use the plt.show()
But convert the plot to numpy array which has correct (4,6) size but surprisingly fill the plot by stretched to only bbox of the draw line
How can i see all the unused space of figure?
Is there any flag that i have to change in somewhere in matplotlib?
Any help appreciated
The plot of matplotlib will define the output based on shape and size of drawing not based on the pre-defined figure size,some kind of back-end and front-end, or simply it is a responsive-layout when you resize the window everything will scale else those are passed through linewidth= and ...
then i changed my workflow and problem solved ;)
I'd like to draw a 2D time series in color with flutter.
Goal
Obviously, it's different from 1D data in that along the y-axis I have a vector of discrete data points at each x, but the color graph must be continuous. So I'd love to use color gradients between these data points to present a continuous heat map.
The end result would look like a spectrogram
With Python's matplotlib, this would be a simple imshow() call.
Reference
From this question: How to do a Gradient effect from topLeft to botttomRgiht in Flutter Shader?
I learned that I could use flutter's shader to create color gradients. That's fine.
Problem
But it seems to me that I would need hundreds of shaders between the data points in order to draw dynamic gradients I want. The y-vector could be as big as 1000 to 2000 data points at each moment.
Is there a simpler way to achieve what I want, such as using as few shaders as possible?