For some reason I cannot find any examples online for what I'm trying to do.
I have an array where each point is [x,y,f(x,y)]. The x,y values cover the 2d space evenly and without repeating.
I want to create a 2D density plot where each point is colored according to its z value.
If I plot this data in Mathematica as a 3D surface and look at it from above, it looks like this: https://imgur.com/a/m4Rt0ui
I would like to make this, except 2D and in python.
Related
I have a 3D array (created by performing 2D scans at different depths), filled with measurement values. Most values are rather low, while some will be locally higher. I would like to plot these like this in python:
But I have not been able to find a good option for that. Note that the pixel size in XY and Z can be different. Matplotlib would be easiest, but I'm open to other options as well.
I'm trying to visualise a dataset in 3D which consists of a (along y axis - constant values) of x-z data, using Python and Matplotlib. In other words, I have measured T(t) (z(x)) data of 16 points (y-axis)
I'd like to create something like picture below, I only managed to create enter image description here, but from this is not useful to see the desired peaks.
So ideally I would like to be looking something like this.
enter image description here
I have a 3 column irregular data in the format [X Y Z]. I am having difficulty in creating a contourf
plot for the same since it requires one to create a meshgrid and also that data be uniform among the grid.
I need some direction or hint to get started.
I am providing two ways in which you can create a contour/density plot for the data which is in 3-column format and irregular, as you have mentioned.
You can use Mathematica: see the documentation of ListDensityPlot. You can directly provide the data as, ListDensityPlot[{{x1,y1,f1},…,{xk,yk,fk}}], and this will plot the sought density plot.
There is also a simple way to do this in python: You can see the documentation of tricontourf, a module of matplotlib. Its functionality is similar to that of contourf, except that you give 1D arrays rather than the data in mesh grid format.
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.
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