How can i plot a boundary line in contour plot

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 comentarios

Wan Ji
Wan Ji el 22 de Ag. de 2021
Editada: Wan Ji el 22 de Ag. de 2021
the dark points refer to what?
The dark points is dark blue points in the attached figure at the corners of figure.
Adam Danz
Adam Danz el 23 de Ag. de 2021
Why are you changing the default font properties instead of specifying them for each figure/axes? I've commented-out those lines in your code so users who copy-paste-run the code won't have to deal with changes to their default properties and since they are not related to the problem.
Adam Danz
Adam Danz el 23 de Ag. de 2021
When I run your code, g contains imaginary numbers which result in an error in contour().
Adam Danz
Adam Danz el 23 de Ag. de 2021
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.

Iniciar sesión para comentar.

 Respuesta aceptada

Adam Danz
Adam Danz el 23 de Ag. de 2021
Editada: Adam Danz el 23 de Ag. de 2021
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 comentarios

mohammad mortezaie
mohammad mortezaie el 23 de Ag. de 2021
Editada: mohammad mortezaie el 23 de Ag. de 2021
Thank you so much but I want a hexagonal shape when the dark points are connecting.
circle shape is not true for my porpuse.
Adam Danz
Adam Danz el 23 de Ag. de 2021
Answer updated.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Contour Plots en Centro de ayuda y File Exchange.

Preguntada:

el 22 de Ag. de 2021

Comentada:

el 23 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by