How to plot UNEQUAL x -y axis for 3D surface plot
34 views (last 30 days)
Show older comments
Hello everyone,
I have data in the form of x,y, z that I want to plot as a surface plot. For x I have time points, eg. x = [0 2 5 7 9 11 15] and for 4 different conditions measurements were taken at y = [200 400 900 2100]. To each time point z corresponds to each of the 4 conditions so the matrix I have in excel looks a bit like this:
x y z
200 0 1626,8467
400 0 1259,2767
900 0 1019,4433
2100 0 741,7067
200 0,2857 1616,9833
400 0,2857 1230,79
900 0,2857 1018,78
2100 0,2857 792,2667
200 0,7143 1403,5167
400 0,7143 932,41
900 0,7143 624,98
2100 0,7143 427,3167
I want the plot to kinda look like this plot from SigmaPlot. I've been using this program for plotting. But since I want to change the colormap to a perceptually uniform colormap that is not availabe in my version, I'm trying to move to Matlab.
I've tried a few different methods to plot this as surface in matlab but yet did not get a nice result. I've been mostly orientating myself on this document:
%EXAMPLE.M
%Example of 3-D plot in Matlab
%Experimental data isn't always spaced perfectly, so neither is
%the data for this example
%Here's the x data
x=[0 1.1 2 3.2 4 5 6 7 8 9
.1 1 2.2 3 4 5 6 7 8 9
0 1 2.1 3 4 5 6 7 8 9
0 1 2 3.1 4 5 6 7 8 9
.1 1 2.1 3 4.1 5 6 7 8 9
0 1.1 2 3.2 4 5 6 7 8 9
.1 1 2.2 3 4 5 6 7 8 9
0 1 2.1 3 4 5 6 7 8 9
0 1 2 3.1 4 5 6 7 8 9
.1 1 2.1 3 4.1 5 6 7 8 9];
%Here's the y data
%a
y=[0 1.1 2 3.2 4 5 6 7 8 9
.1 1 2.2 3 4 5 6 7 8 9
0 1 2.1 3 4 5 6 7 8 9
0 1 2 3.1 4 5 6 7 8 9
.1 1 2.1 3 4.1 5 6 7 8 9
0 1.1 2 3.2 4 5 6 7 8 9
.1 1 2.2 3 4 5 6 7 8 9
0 1 2.1 3 4 5 6 7 8 9
0 1 2 3.1 4 5 6 7 8 9
.1 1 2.1 3 4.1 5 6 7 8 9]';
%Here's the z data
z=[0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 1 1 0 0
0 1 1 2 2 2 2 1 1 0
0 1 2 2 3 3 2 2 1 0
0 1 2 3 4 4 3 2 1 0
0 1 2 3 4 4 3 2 1 0
0 1 2 2 3 3 2 2 1 0
0 1 1 2 2 2 2 1 1 0
0 0 1 1 1 1 1 1 0 0
0 0 0 0 0 0 0 0 0 0];
%There are several ways to do 3-D plots, here are a few
%plot3(x,y,z)
%mesh(x,y,z)
surf(x,y,z)
%Note: Matlab is case sensitive, so X and x aren't the same thing.
%mesh(x,y,z)
%end EXAMPLE.M
1)
with surf (x,y,z) I can plot a surface I want, but as far as I understand, surf only takes matrices of equal dimensions on x and y ?
So I only get as far as 4x4 since my x only has 4 values, that keep on repeating. Also the surface is plotted in the wrong plane.
2) trying to take in more data points I transformed my x, y and z data to 10x10 matrices. I did this manually in the workspace, as I haven't found the proper code for transformation yet. Again plotting with surf (x,y,z)
Now this looks closer to what I want, but I guess due to the matrix dimensions, the point connections and planes are wrong.
Can anyone offer me a solution for my data organisation?
0 Comments
Accepted Answer
Hrishikesh Borate
on 3 Feb 2021
Hi,
I understand that you are trying to plot data with unequal x and y axes. You can use meshgrid to organize the data. For other plotting options refer to surface and mesh plots.
2 Comments
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!