Confine contour lines to region defined by data
I am using contour() to construct contour lines onto a 2D grid of data defined by the first two columns of "tog.txt," with the value defined by the third column. This data can have 10^3 or more rows. I would like to confine these lines to exist only in the region where the data exists.
I plot the scatter data as well as the border that bounds the data with boundary() for visualization.
The results of each attempt are attached. How can I ensure the contour lines are terminated by the data boundary?
togtxt = load(‘tog.txt’);
x1 = togtxt(:,1);
y1 = togtxt(:,2);
c1 = togtxt(:,3);
% —- customize figure ——————————————————-
f(1)=figure;
hold all
ax = gca;
set(gca,’LineWidth’,1.3,’TickLength’,[0.015 0.015],’plotboxaspectratio’,[1 1 1]); % size of ticks
set(gca,’ColorScale’,’log’)
xscale log
jjj = boundary(x1,y1);
plot(x1(jjj),y1(jjj));
scatter(togtxt(:,1),togtxt(:,2),2,’filled’);
N = 120;
%%% attempt 1
v1 = logspace(log10(min(c1)),log10(max(c1)),50);
I = scatteredInterpolant(x1,y1,c1);
X = linspace(min(x1),max(x1),N);
Y = linspace(min(y1),max(y1),N);
[X,Y] = meshgrid(X,Y);
Z = I(X,Y);
contour(X,Y,Z,v1);
colorbar
%%% attempt 2
% v1 = logspace(log10(min(c1)),log10(max(c1)),50);
% xv = linspace(min(x1),max(x1),N);
% yv = linspace(min(y1),max(y1),N); % will run out of memory unless N small
% [Xm,Ym] = ndgrid(xv,yv);
% MFm = griddata(x1,y1,c1,Xm,Ym);
% contour(Xm, Ym, MFm,v1)I am using contour() to construct contour lines onto a 2D grid of data defined by the first two columns of "tog.txt," with the value defined by the third column. This data can have 10^3 or more rows. I would like to confine these lines to exist only in the region where the data exists.
I plot the scatter data as well as the border that bounds the data with boundary() for visualization.
The results of each attempt are attached. How can I ensure the contour lines are terminated by the data boundary?
togtxt = load(‘tog.txt’);
x1 = togtxt(:,1);
y1 = togtxt(:,2);
c1 = togtxt(:,3);
% —- customize figure ——————————————————-
f(1)=figure;
hold all
ax = gca;
set(gca,’LineWidth’,1.3,’TickLength’,[0.015 0.015],’plotboxaspectratio’,[1 1 1]); % size of ticks
set(gca,’ColorScale’,’log’)
xscale log
jjj = boundary(x1,y1);
plot(x1(jjj),y1(jjj));
scatter(togtxt(:,1),togtxt(:,2),2,’filled’);
N = 120;
%%% attempt 1
v1 = logspace(log10(min(c1)),log10(max(c1)),50);
I = scatteredInterpolant(x1,y1,c1);
X = linspace(min(x1),max(x1),N);
Y = linspace(min(y1),max(y1),N);
[X,Y] = meshgrid(X,Y);
Z = I(X,Y);
contour(X,Y,Z,v1);
colorbar
%%% attempt 2
% v1 = logspace(log10(min(c1)),log10(max(c1)),50);
% xv = linspace(min(x1),max(x1),N);
% yv = linspace(min(y1),max(y1),N); % will run out of memory unless N small
% [Xm,Ym] = ndgrid(xv,yv);
% MFm = griddata(x1,y1,c1,Xm,Ym);
% contour(Xm, Ym, MFm,v1) I am using contour() to construct contour lines onto a 2D grid of data defined by the first two columns of "tog.txt," with the value defined by the third column. This data can have 10^3 or more rows. I would like to confine these lines to exist only in the region where the data exists.
I plot the scatter data as well as the border that bounds the data with boundary() for visualization.
The results of each attempt are attached. How can I ensure the contour lines are terminated by the data boundary?
togtxt = load(‘tog.txt’);
x1 = togtxt(:,1);
y1 = togtxt(:,2);
c1 = togtxt(:,3);
% —- customize figure ——————————————————-
f(1)=figure;
hold all
ax = gca;
set(gca,’LineWidth’,1.3,’TickLength’,[0.015 0.015],’plotboxaspectratio’,[1 1 1]); % size of ticks
set(gca,’ColorScale’,’log’)
xscale log
jjj = boundary(x1,y1);
plot(x1(jjj),y1(jjj));
scatter(togtxt(:,1),togtxt(:,2),2,’filled’);
N = 120;
%%% attempt 1
v1 = logspace(log10(min(c1)),log10(max(c1)),50);
I = scatteredInterpolant(x1,y1,c1);
X = linspace(min(x1),max(x1),N);
Y = linspace(min(y1),max(y1),N);
[X,Y] = meshgrid(X,Y);
Z = I(X,Y);
contour(X,Y,Z,v1);
colorbar
%%% attempt 2
% v1 = logspace(log10(min(c1)),log10(max(c1)),50);
% xv = linspace(min(x1),max(x1),N);
% yv = linspace(min(y1),max(y1),N); % will run out of memory unless N small
% [Xm,Ym] = ndgrid(xv,yv);
% MFm = griddata(x1,y1,c1,Xm,Ym);
% contour(Xm, Ym, MFm,v1) meshgrid, contour MATLAB Answers — New Questions