how to separate two graphe in one figure

34 ビュー (過去 30 日間)
Belaid
Belaid 2024 年 11 月 26 日 14:47
コメント済み: Image Analyst 2024 年 11 月 29 日 15:21
how to separate two graphe in one figure like this picture in matlab

採用された回答

Subhajyoti
Subhajyoti 2024 年 11 月 26 日 15:00
編集済み: Subhajyoti 2024 年 11 月 26 日 15:06
It is my understanding that you want to draw multiple plots on the same axes. You can use 'hold on' to retains the plots in the current axes so that new plots added to the axes do not delete existing plots.
Here, in the following implementation, I have added a surface plot and a 3D line plot on the same same using the same.
% Define the grid
[x, y] = meshgrid(linspace(-1, 1, 100), linspace(-1, 1, 100));
% Define the surface function
z1 = sin(pi*x).*cos(pi*y);
% Define the second graph (e.g., a circle with noise)
theta = linspace(0, 2*pi, 100);
r = 0.5 + 0.1*rand(1, 100); % Add some noise
x2 = r .* cos(theta);
y2 = r .* sin(theta);
z2 = -2 * ones(size(x2)); % Place it below the surface
% Create the figure
figure;
% Plot the surface
surf(x, y, z1, 'EdgeColor', 'none');
hold on;
% Plot the second graph
plot3(x2, y2, z2, 'b-', 'LineWidth', 2);
plot3(x2, y2, z2, 'r.', 'MarkerSize', 10);
% Customize the view
colormap('jet');
colorbar;
xlabel('x');
ylabel('y');
zlabel('z');
grid on;
hold off;
Refer to the following MathWorks Documentation to know more about 'hold' and '3D Plots' in MATLAB Graphics:
  2 件のコメント
Belaid
Belaid 2024 年 11 月 28 日 14:15
thnx ,is work
Belaid
Belaid 2024 年 11 月 29 日 14:46
how can plot the curve gare with equation 1+(1/10)*tanh(10*sin(25t)) in the boundary and analytical function u(x,y)=exp(2.*x+y)+sin(pi.*x).*cosh(y); to find the graphe like picture
% Define the grid
[x, y] = meshgrid(linspace(0, 2*pi, 1000), linspace(0, 2*pi, 1000));
%r=cos(2.*x).^2.*exp(cos(x)) + sin(2.*y).^2.*exp(sin(y));
% r=sqrt(cos(2.*x)+sqrt(1.1-sin(2.*x).^2));
r=1+1/10*tanh(10*sin(25*x));
r1=1+1/10*tanh(10*sin(25*y));
x1 = r .* cos(x);
y1 = r .* sin(y);
% Define the surface function
z1=exp(2.*x1+y1)+sin(pi.*x1).*cosh(y1);
% Define the second graph (e.g., a circle with noise)
theta = linspace(0, 2*pi, 100);
%r = 0.5 + 0.1*rand(1, 100);
% r=sqrt(cos(2.*theta)+sqrt(1.1-sin(2.*theta).^2));
%r=cos(2.*theta).^2.*exp(cos(theta)) + sin(2.*theta).^2.*exp(sin(theta));
r=1+1/10*tanh(10*sin(25*theta));
% Add some noise
x2 = r .* cos(theta);
y2 = r .* sin(theta);
z2 = -2 * ones(size(x2)); % Place it below the surface
% Create the figure
figure;
% Plot the surface
surf(x1, y1, z1, 'EdgeColor', 'none');
hold on;
% Plot the second graph
plot3(x2, y2, z2, 'b-', 'LineWidth', 2);
% plot3(x2, y2, z2, 'r.', 'MarkerSize', 10);
% Customize the view
colormap('jet');
colorbar;
xlabel('x');
ylabel('y');
zlabel('z');
grid on;
hold off;

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2024 年 11 月 26 日 15:16
If you want one plot or surface to be "lifted" above the other, you can add an offset to the one you want shifted. Be aware that the axes units will not align with the original units, but with the shifted units.
  4 件のコメント
Belaid
Belaid 2024 年 11 月 29 日 14:47
編集済み: Image Analyst 2024 年 11 月 29 日 15:19
How can plot the curve gare with equation 1+(1/10)*tanh(10*sin(25t)) in the boundary and analytical function u(x,y)=exp(2.*x+y)+sin(pi.*x).*cosh(y); to find the graph like picture?
% Define the grid
[x, y] = meshgrid(linspace(0, 2*pi, 1000), linspace(0, 2*pi, 1000));
%r=cos(2.*x).^2.*exp(cos(x)) + sin(2.*y).^2.*exp(sin(y));
% r=sqrt(cos(2.*x)+sqrt(1.1-sin(2.*x).^2));
r=1+1/10*tanh(10*sin(25*x));
r1=1+1/10*tanh(10*sin(25*y));
x1 = r .* cos(x);
y1 = r .* sin(y);
% Define the surface function
z1=exp(2.*x1+y1)+sin(pi.*x1).*cosh(y1);
% Define the second graph (e.g., a circle with noise)
theta = linspace(0, 2*pi, 100);
%r = 0.5 + 0.1*rand(1, 100);
% r=sqrt(cos(2.*theta)+sqrt(1.1-sin(2.*theta).^2));
%r=cos(2.*theta).^2.*exp(cos(theta)) + sin(2.*theta).^2.*exp(sin(theta));
r=1+1/10*tanh(10*sin(25*theta));
% Add some noise
x2 = r .* cos(theta);
y2 = r .* sin(theta);
z2 = -2 * ones(size(x2)); % Place it below the surface
% Create the figure
figure;
% Plot the surface
surf(x1, y1, z1, 'EdgeColor', 'none');
hold on;
% Plot the second graph
plot3(x2, y2, z2, 'b-', 'LineWidth', 2);
% plot3(x2, y2, z2, 'r.', 'MarkerSize', 10);
% Customize the view
colormap('jet');
colorbar;
xlabel('x');
ylabel('y');
zlabel('z');
grid on;
hold off;
Image Analyst
Image Analyst 2024 年 11 月 29 日 15:21
I don't understand the question. What is t? Is it x or y? And if it's one of those, what value would the other x or y have? Maybe you should start your own question rather than continue here in @Belaid Boutqlmount's question (for which he'll get emails about).

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

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by