I have some issues with contour plotting. Below is the similar data:
x= [0 0.1 0.2 0.3 0.4 0.5 0 0.1 0.2 0.3 0.4 0.5 0 0.1 0.2 0.3 0.4 0.5 0 0.1 0.2 0.3 0.4 0.5 0 0.1 0.2 0.3 0.4 0.5];y = [0 0.01 0.02 0.022 0.024 0.025 0 0.012 0.022 0.03 0.032 0.033 0 0.02 0.03 0.035 0.037 0.038 0 0.022 0.042 0.052 0.061 0.062 0 0.03 0.04 0.07 0.91 0.98];g = [1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 5 5 5 5 5 5];z = [0 5.1 6 5.8 5.2 2.4 0 5.2 6.2 5.9 5.3 2.7 0 5.4 6.4 6.1 5.4 3.0 0 5.3 6.1 5.6 4.8 2.8 0 5.0 5.9 5.2 4.3 2.1];Plotdata = [x' y' g' z']Plotdata = 0 0 1.0000 0 0.1000 0.0100 1.0000 5.1000 0.2000 0.0200 1.0000 6.0000 0.3000 0.0220 1.0000 5.8000 0.4000 0.0240 1.0000 5.2000 0.5000 0.0250 1.0000 2.4000 0 0 2.0000 0 0.1000 0.0120 2.0000 5.2000 0.2000 0.0220 2.0000 6.2000 0.3000 0.0300 2.0000 5.9000 0.4000 0.0320 2.0000 5.3000 0.5000 0.0330 2.0000 2.7000 0 0 3.0000 0 0.1000 0.0200 3.0000 5.4000 0.2000 0.0300 3.0000 6.4000 0.3000 0.0350 3.0000 6.1000 0.4000 0.0370 3.0000 5.4000 0.5000 0.0380 3.0000 3.0000 0 0 4.0000 0 0.1000 0.0220 4.0000 5.3000 0.2000 0.0420 4.0000 6.1000 0.3000 0.0520 4.0000 5.6000 0.4000 0.0610 4.0000 4.8000 0.5000 0.0620 4.0000 2.8000 0 0 5.0000 0 0.1000 0.0300 5.0000 5.0000 0.2000 0.0400 5.0000 5.9000 0.3000 0.0700 5.0000 5.2000 0.4000 0.9100 5.0000 4.3000 0.5000 0.9800 5.0000 2.1000
In the data, x and y would be plotted with g as group numbers:
hold onsplitapply(@(x,y)plot(x,y,'LineWidth',1.5,'marker','.','markersize',10,'MarkerEdgeColor',[1 0 1],'color',[1 0 1]),Plotdata(:,1),Plotdata(:,2),findgroups(Plotdata(:,3)))
The 2D plot created from x,y and g is shown as below:
My question is how to plot z as contour on top of this 2D plot?
The desired contour plot is shown as below. I drew the contour diagram in powerpoint (not real data).
I tried many times with contourf plot, meshgrid and griddata functions.
But I am not sure what is the best way to realize this kind plot. Can you help me with this problem?
Best Answer