Which python lib for plotting 3D particles - python

I am new to python and one of my assignments I am doing is asking to, "Write a program that puts identical non-overlapping particles of diameter d in a cubic (3d) lattice with periodic boundary conditions. The linear length is L. Write the program in such a way that you can vary the number of particles. Demonstrate that your program works and show at least one visualization"
I am looking to see what 3D lib I should use, any suggestions?
Also, any suggestions on how I should approach this problem? I'd imagine i can randomly generate the x,y,z coordiantes of the n number of particles I have the user input. How can I ensure they do not overlap though? I am also confused on the "periodic boundary conditions" but thats not python related :|
Thanks for the help in advance!!

Matplotlib works fine for simple 3D plots and is very popular so it's easy to find documentation, tutorials and help. However, for something specifically geared to 3D plots, try Mayavi.

Related

How to make a plot that connect its points to its closest neighbors?

I am working on a code to project a given object onto a plane.
The code works fine (at least it seems like it) in achieving that purpose, the only issue I'm having is in plotting my results.
In the image below, for instance, I'm plotting the projection of a parallelepiped (its edges, to be more precise) in a plane of my choice.
I would like to make a plot where each point is connected to its closest neighbor. I'm not very confident that this approach would get the job done, but I think it would be worth the shot.
Different ideas to get there are also welcome!
Any thoughts?
Thanks in advance.
Note: I also tried using a solid line style when plotting as opposed to the pixel marker style, but the result I got was not quite what I expected to say the least:
When telling matplotlib to plot a sequence of points and join them with a line, it creates a straight line between two adjacent points in your input data. To create several lines, it's often easier to split your plot command into several ones. An alternative is to arrange your points such that they form the edges you want, but that would be much more complicated in your case.
As discussed in the comments, separating each edge into its own separate plot command worked for your case.

How to plot a cube or parallelepid with function-related color map

I am unfortunately quite inexperienced with python, and programming in general. I am devoting a lot of time to get better but this one really got me.
I need to evaluate a time evolving funtion happening within the boundaries of a solid, a cube if you like.
My idea was to plot a 3D surface with x, y and z being the dimensions of my solid, and the colormap being the values of the function i mentioned at a given point in time. The final result would be a video with the sequence of plots for a given time interval.
I smashed my head with matplotlib recently but I don't seem to understand the idea behind the need for numpy 2D arrays for surface plotting. The examples given in the docs are somewhat not revelant as my function values come from a numerical solution, hence there is no explicit relation between x,y and z and F(x,y,z).
Does anyone have any suggestion? I hope I haven't been negligent on the doc reading on the topic.

Plotting 3D Chessboard/Swiss Cheese Type Patterns in Python

My particular case is that I am trying to make a 3D space-time diagram of a 2D cellular automata. If anybody has any advice/clever ways of representing this visually that would be awesome, but to make the question more general I'll phrase it as...
What is the best way to plot a sort of 3D chessboard or Swiss Cheese type pattern where the white squares are transparent (or vice versa)?
I have looked around and have found ways to plot Imshow type plots on a 3D coordinate system, but it was kind of clunky, slow, and I couldn't get the transparency to work (didn't try masks, but it didn't seem like what I wanted, but I could be wrong).
I have also used a scatter plot where I have a point at (x,y,z) if cell (x,y) is in the active state at time z (also tried the other way around...). This actually managed to render and looked pretty cool, but for the wrong reasons since it was hard to see anything on and was hard to angle properly due to the amount of points on the scatter plots making it lag.
Thanks in advance for any advice.

Best way to create a 2D Contour Map with Python

I am trying to create a 2D Contour Map in Python that looks like this:
In this case, it is a map of chemical concentration for a number of points on the map. But for the sake of simplicity, we could just say it's elevation.
I am given the map, in this case 562 by 404px. I am given a number of X & Y coordinates with the given value at that point. I am not given enough points to smoothly connect the line, and sometimes very few data points to draw from. It's my understanding that Spline plots should be used to smoothly connect the points.
I see that there are a number of libraries out there for Python which assist in creation of the contour maps similar to this.
Matplotlib's Pyplot Contour looks promising.
Numpy also looks to have some potential
But to me, I don't see a clear winner. I'm not really sure where to start, being new to this programming graphical data such as this.
So my question really is, what's the best library to use? Simpler would be preferred. Any insight you could provide that would help get me started the proper way would be fantastic.
Thank you.
In the numpy example that you show, the author is actually using Matplotlib. While there are several plotting libraries, Matplotlib is the most popular for simple 2D plots like this. I'd probably use that unless there is a compelling reason not to.
A general strategy would be to try to find something that looks like what you want in the Matplotlib example gallery and then modify the source code. Another good source of high quality Matplotlib examples that I like is:
http://astroml.github.com/book_figures/
Numpy is actually a N-dimensional array object, not a plotting package.
You don't need every pixel with data. Simply mask your data array. Matplotlib will automatically plot the area that it can and leave other area blank.
I was having this same question. I found that matplotlib has interpolation which can be used to smoothly connect discrete X-Y points.
See the following docs for what helped me through:
Matplotlib's matplotlib.tri.LinearTriInterpolator docs.
Matplotlib's Contour Plot of Irregularly Spaced Data example
How I used the above resources loading x, y, z points in from a CSV to make a topomap end-to-end

Interactive 2D plotting in python

I'm trying to write a program that creates a 2D grid in which the user chooses some edges between the points in the grid. Then the program dynamically manipulate those edges(eg. flip them, connect them, ...) till it converges to a particular shape.
Now my question is there any particular module that suits this kind of interactive plotting.
So far I've looked into PyQwt, GuiQwt, and Chaco but cannot figure out which one is more applicable for my program. It be great if someone could compare and contrast them, or suggest new modules.
Thanks
Have you tried PyGame or SFML?
Both support 'setting pixels' on a canvas.

Categories