How can i plot a boundary line in contour plot

6 次查看(过去 30 天)
Hello,
I have this code for ploting a contour plot.
%bare electron mass (kg)
a=1.855;
eb=-3.276;
ep=-1.979;
t=-1.844;
FS = 24; %label fontsize
FSN = 24; %number fontsize
LW = 2; %linewidth
% Change default axes fonts.
% set(0,'DefaultAxesFontName', 'Times New Roman');
% set(0,'DefaultAxesFontSize', FSN);
% Change default text fonts.
% set(0,'DefaultTextFontname', 'Times New Roman');
% set(0,'DefaultTextFontSize', FSN);
hbarChar=['\fontname{MT Extra}h\fontname{Times New Roman}'];
iform = complex(0.0,1.0);
% Creating necessary k-vectors
kx = linspace(-1.4,1.4,500);
ky = linspace(-2,2,500);
[k_x,k_y] = meshgrid(kx, ky);
phi=exp(-iform.*k_x*a)+2.*exp(iform.*k_x*a/2).*cos(sqrt(3).*k_y.*a/2);
figure (2)
energy_mesh1 = (eb+ep)/2+sqrt(((eb-ep)/2)^2+t^2.*phi.*conj(phi)) ;
energy_mesh2 = (eb+ep)/2-sqrt(((eb-ep)/2)^2+t^2.*phi.*conj(phi));
g=energy_mesh1-energy_mesh2;
contour(k_x,k_y,g,500,'LineWidth',1.5)
colormap('jet');
I want to connect dark points of the contour plot.
What should I do?
  5 个评论
Adam Danz
Adam Danz 2021-8-23
When I run your code, g contains imaginary numbers which result in an error in contour().
Adam Danz
Adam Danz 2021-8-23
I have the same question as @Wan Ji. What are the dark points (your image didn't help) and how do you want to connect them? With lines? Perhaps an illustration would help.

请先登录,再进行评论。

采纳的回答

Adam Danz
Adam Danz 2021-8-23
编辑:Adam Danz 2021-8-23
Copy of original code with the following changes.
  • contour(k_x,k_y,g,500) chaanged to contour(k_x,k_y,real(g),500)
  • Commented-out changes to default font properties
%bare electron mass (kg)
a=1.855;
eb=-3.276;
ep=-1.979;
t=-1.844;
FS = 24; %label fontsize
FSN = 24; %number fontsize
LW = 2; %linewidth
% Change default axes fonts.
% set(0,'DefaultAxesFontName', 'Times New Roman');
% set(0,'DefaultAxesFontSize', FSN);
% Change default text fonts.
% set(0,'DefaultTextFontname', 'Times New Roman');
% set(0,'DefaultTextFontSize', FSN);
hbarChar=['\fontname{MT Extra}h\fontname{Times New Roman}'];
iform = complex(0.0,1.0);
% Creating necessary k-vectors
kx = linspace(-1.4,1.4,500);
ky = linspace(-2,2,500);
[k_x,k_y] = meshgrid(kx, ky);
phi=exp(-iform.*k_x*a)+2.*exp(iform.*k_x*a/2).*cos(sqrt(3).*k_y.*a/2);
figure (2)
energy_mesh1 = (eb+ep)/2+sqrt(((eb-ep)/2)^2+t^2.*phi.*conj(phi)) ;
energy_mesh2 = (eb+ep)/2-sqrt(((eb-ep)/2)^2+t^2.*phi.*conj(phi));
g=energy_mesh1-energy_mesh2;
contour(k_x,k_y,real(g),500)
colormap('jet');
Compute the location of lowest values excluding the image edges
% Get lowest points
idx = find(imregionalmax(-real(g)));
% Remove lowest points at edges
[row,col] = ind2sub(size(g),idx);
isEdge = row==1 | row==size(g,1) | col==1 | col==size(g,2);
idx(isEdge) = [];
Compute center and radius of circle
This assumes that the points will lie along the circumference of a circle. If the expected shape is oval, that's an easy change. If the expected shape is unknown, you'll need to sort the points so they are in order and then just plot their connections with a line or compute a polyshape.
% compute circle
xyLoc = [k_x(idx),k_y(idx)];
cnt = mean(xyLoc);
radius = max(range(xyLoc))/2;
% Plot points and circle
axis equal
hold on
h = plot(k_x(idx),k_y(idx), '*w','MarkerSize', 14);
circ = rectangle('Position',[cnt-radius, [2,2]*radius], ...
'Curvature',[1,1], 'EdgeColor', 'w');
Linear connections
First you have to sort the coordinates.
[th, ~] = cart2pol(xyLoc(:,1),xyLoc(:,2));
[~, sortIdx] = sort(th);
xyLocSort = xyLoc(sortIdx,:);
xyLocSort = [xyLocSort; xyLocSort(1,:)]; % wrap polygon
h = plot(xyLocSort(:,1), xyLocSort(:,2), 'w-');
  2 个评论
mohammad mortezaie
mohammad mortezaie 2021-8-23
编辑:mohammad mortezaie 2021-8-23
Thank you so much but I want a hexagonal shape when the dark points are connecting.
circle shape is not true for my porpuse.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by