フィルターのクリア

How can i plot a boundary line in contour plot

2 ビュー (過去 30 日間)
mohammad mortezaie
mohammad mortezaie 2021 年 8 月 22 日
コメント済み: Adam Danz 2021 年 8 月 23 日
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.
Adam Danz
Adam Danz 2021 年 8 月 23 日
Answer updated.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by