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.
Related
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.
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.
The dataset is large with over 15000 rows.
One row of x,y,z plots a point on a 3D plot.
I need to scale the data and so far I'm using RobustScaler(), but I want to make sure that the dataset is either normally distributed or it isn't.
Matplotlib histogram [plt.hist()] can be used for checking data distribution. If the highest peak middle of the graph, then datasets are normally distributed.
I'm looking for away to directly convert my 2D array to the RGB data of matplotlib's matshow() method. What I've acknowledged from the source code is that it uses imshow() method, which sets some hyperparameters and then calls add_image(), in which based on https://github.com/matplotlib/matplotlib/blob/1722bfd6ae4fac707811c8e8dca171138cb5d2a6/lib/matplotlib/axes/_base.py calls append(image). And I'm stuck from this.
So, is there any way to directly map a raw 2D array to image RGB array after matshow() method (with colormap integrated) without calling the plotting?
Edit: In case that my above explanation is hard to understand, I have a 2D matrix (not a grayscale image array). I'm gonna plot it using matshow() with a certain colormap, and vmin & vmax values. I can extract the image pixel values as a 3D array using fig.canvas.show() and np.fromstring() as in here. However my application has very strict time constraint that plotting the data would take too much time (and also very unstable). So instead of plotting (which sequentially call figure(), subplot(), matshow()...) I want to get the 3D image data directly (through some mapping) from my original 2D matrix. I believe it is possible if I understand how pyplot maps the data, but unfortunately I couldn't find the solution in their source code yet.
I am using pcolor in matplotlib. I use a three dimensional array as the input. I want to arrange the third array to be displayed in a log scale. Is there an option to do this? If I take a logarithm of the third array before plotting it, the sub one values become negative and pcolor no longer works.