Combine a contour plot with a simple 2D plot with same x axis
Show older comments
I have two datasets from which I can make a 2D density plot and a simple 2D plot.
For both plots, the x axis coordinates have the same range. Thus, I would like to merge the two plots into just one figure. What I want to obtain looks very similar to the figure below.

So far I have tried the following:
clear all;
close all;
clc
A = importdata("spectrum.dat"); %importing the data file
x = A(:,1); %extracting the values of the 1st column
y = A(:,2); %extracting the values of the 2nd column
z = A(:,3); %extracting the values of the 3rd column
B = importdata("qpwdata.dat");
a = B(:,1);
b = B(:,2);
figure(1)
plot(a,b,'LineWidth',3)
set(gca,'FontSize',15)
xlim([60 105])
ylim([0 1.2])
xticks([60 65 70 75 80 85 90 95 100 105])
yticks([0 0.2 0.4 0.6 0.8 1.0 1.2])
xlabel('\textbf{B(G)}', 'interpreter', 'latex', 'FontWeight','bold', 'FontSize', 20, 'FontName', 'Times New Roman');
ylabel('$\textbf{Z}$','interpreter', 'latex', 'FontName', 'Times New Roman','Fontsize',20);
tri = delaunay(x,y); %performing the Delaunay triangulation
figure(2)
trisurf(tri,x,y,z) %creating the surface plot
set(gca,'FontSize',15) %changing the values of the axis values -> make them bigger
xlim([60 105])
ylim([-5 5])
xticks([60 65 70 75 80 85 90 95 100 105])
yticks([-5 -4 -3 -2 -1 0 1 2 3 4 5])
xlabel('\textbf{B(G)}', 'interpreter', 'latex', 'FontWeight','bold', 'FontSize', 20, 'FontName', 'Times New Roman');
ylabel('$\textbf{En}^{-2/3}$','interpreter', 'latex', 'FontName', 'Times New Roman','Fontsize',20);
colormap jet
colorbar %inserting the colorbar
shading interp
view(2) %projecting the 3D surface into the 2D plane
what gives me the two plots separately.


I wonder how I can have both plots as in shown in the Figure above.
I have read that the function stackedplot does the job, but I have not understood how I would apply it in my problem.
Accepted Answer
More Answers (0)
Categories
Find more on Discrete Data 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!

