Plotting 3D Electric Potential and Field Lines in Python - python

My goal is to create a 3d plot of the field inside a Paul trap. I've been trying to do this 3D plot without any success. My problem is that I have a 3D matrix that represents the potential everywhere in space, but I haven't found a way to plot it as a contour or color map.
All the options I saw required me to create a meshgrid of x and y and then plot z as a function of x and y, which isn't what I need because the potential depends on all 3 coordinates. Does anyone know of a function to plot in such a way, or at least a way to trick other functions into doing what I need?
Thank you in advance!

Related

In python, is it possible to plot colour map by giving coordinates and function value?

On the web, the only solution I find to plot the values of a two-dimensional function is to have a file with the matrix A(nxm) of the function's values and use matplotlib imshow. This will produce a map, whose extent (dimension along axes) has to be known and explicitly indicated.
Now, my concern arises from the fact that I need to plot two maps on the same axis, but one is slanted with respect to the other. So to say, I have a large main rectangular map and a smaller one that is oblique and superimposed.
In the end, the question is: is it possible to plot 2d maps starting from a file that is written as x, y, f(x,y) rather than just using f(x,y) so the plotting tool knows exactly where to draw?
I luckily found what I was looking for in pcolormesh that can draw a map given the coordinates of each point and its "colour"-value.

Revalue a plot axis

I'm plotting a Matrix with contourf, the Matrix is 883x883, the problem is that when plotting it the axis in the plots go from 0 to 883, but I would like to give it another values, more exactly, I'd like it to go from -20 to 20. How can I set that? I am very new in python, so I'd appreciate your help.
When you use contourf, you can provide the location of your data points using the optional X and Y arguments. This will only work as expected if your data is structured, meaning if you can generate a grid made of rectangles for which the nodes would represent the location of your data points. If this is not the case, then I would suggest using a triangulation and provide it to tricontourf.

How to make data points in a 3D python scatter plot look like "discs" instead of "spheres"

In a standard 3D python plot, each data point is, by default, represented as a sphere in 3D. For the data I'm plotting, the z-axis is very sensitive, while the x and y axes are very general, so is there a way to make each point on the scatter plot spread out over the x and y direction as it normally would with, for example, s=500, but not spread at all along the z-axis? Ideally this would look like a set of stacked discs, rather than overlapping spheres.
Any ideas? I'm relatively new to python and I don't know if there's a way to make custom data points like this with a scatter plot.
I actually was able to do this using the matplotlib.patches library, creating a patch for every data point, and then making it whatever shape I wanted with the help of mpl_toolkits.mplot3d.art3d.
You might look for something called "jittering". Take a look at
Matplotlib: avoiding overlapping datapoints in a "scatter/dot/beeswarm" plot
It works by adding random noise to your data.
Another way might be to reduce the variance of the data on your z-axis (e.g. applying a log-function) or adjusting the scale. You could do that with ax.set_zscale("log"). It is documented here http://matplotlib.org/mpl_toolkits/mplot3d/api.html#mpl_toolkits.mplot3d.axes3d.Axes3D.set_zscale

Pyplot - Drawing a log-log heat map under a curve

I've been struggling with this problem for days, but haven't yet found an answer on the site, so here goes!
I've made a simple straight line plot made in python, using matplotlib.pyplot - It's essentially a triangle, bounded by two straight lines and the y-axis, with a log-log scale. (I can upload the plot if this isn't a clear description, but I've not enough reputation to do so in this post - Sorry!)
The difficult part is, I now need to fill that triangle (and only that area ideally) with a heat map to show the values of a 3rd parameter, which depends on x and y in an extremely complex way. There's no simple function to describe z(x,y), but I have numerical tables giving the values of z at a range of discrete x and y values.
Is it at all possible to create such a graph (especially bearing in mind that the basic plot also has logarithmic axes)?
Thanks for reading!

How do I plot the surface of a 4D plot?

I am trying to plot the wave function for a particle in a 3D box. This requires me to plot 4 variables: x, y, z axes and the probability density function.
The probability density function is:
abs((np.sin((p*np.pi*X)/a))*(np.sin((q*np.pi*Y)/b))*(np.sin((r*np.pi*Z)/c)))**2
I am using np.arange() for the X, Y and Z.
I have read that to do this you need to plot the surface of a 4D plot.
Here is what it is supposed to look like:
You want to plot a 3D scalar field f(x,y,z) against all three spatial coordinates.
I am not sure what you're precisely willing to do: which surfaces are you talking about ? You may want to plot iso-density surfaces, which allow for clear visualization of the field.
I don't know the Matplotlib formulation for this, but with Mayavi2 (a great 3D-plotting Python library) you can use "contour3d" :
http://docs.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html#mayavi.mlab.contour3d
Anyway if you're willing to do advanced 3D stuff Mayavi is way better than Matplotlib.
See the gallery for examples :
http://docs.enthought.com/mayavi/mayavi/auto/examples.html
Hope that helps !
Are these plots essentially plots allowing three of the variables to vary freely while fixing one of the variables and then cycling through all four? If so then these plots could be achieved using matplotlib.Axes3d or the like?

Categories