필터 지우기
필터 지우기

Merge 2D plot with polar plot

조회 수: 3 (최근 30일)
Jorge Luis
Jorge Luis 2024년 1월 15일
댓글: Jorge Luis 2024년 1월 16일
Hello, I would like to merge two different plots in a single one like a 2D plot with a polar plot like it is shown in the image below. I would apreciate the help.
Thank you for your help.
  댓글 수: 2
Mathieu NOE
Mathieu NOE 2024년 1월 15일
hello
it is certainly doable , so what's your issue ?
do you have some data ? code ?
Jorge Luis
Jorge Luis 2024년 1월 16일
Hi, sure. Here I attached the example of the two plots provided in the image. The file plot1.txt is the blue line with x and y coordinates as presented in the two columns respectively. Then, the second plot which is a polar plot should be placed on top of plot 1 whose data is in plot2.txt. Herein, the first column contains the angles and the second column contains the data with same units as plot 1. Thank you.

댓글을 달려면 로그인하십시오.

채택된 답변

Jaime Abad Arredondo
Jaime Abad Arredondo 2024년 1월 16일
As Mathieu said in the comment, what you want to do is definetly doable. As an example:
theta=linspace(0,2*pi,200);
r=3.*cos(2.*theta).^2; %Random made up function.
figure(1)
clf
hold all
p=plot(r.*cos(theta),r.*sin(theta),'r');
%polar(theta,r,'b') %You can generate the polar plots as you wish.
N=50;
x_aux=linspace(-3,3,N);
Z=peaks(N); %Use built-in peaks function as example
surf(x_aux,x_aux,peaks(N))
shading interp
As you can see, the only caveat when mixing 2d and 3d elements in matlab is that the 2d elements are usually drawn at z==0, and therefore the surface plot is overlaid on top of the polar plots. In order to fix this, you have to modify the z-data of the polar plot:
figure(2)
clf
hold all
p=plot(r.*cos(theta),r.*sin(theta),'r');
%polar(theta,r,'b') %You can generate the poar plots as you wish.
N=50;
x_aux=linspace(-3,3,N);
Z=peaks(N);
surf(x_aux,x_aux,peaks(N))
shading interp
%Setting the z-component of the polar plot to be the
% maximum value of the surface plot, so that it appears on top
p.ZData=ones(size(p.XData)).*max(Z(:));

추가 답변 (1개)

Jorge Luis
Jorge Luis 2024년 1월 16일
Hi, thank for your answer and help. Here I provide more details of what I need based on the plot provided in my first question. Here I attached the example of the two plots provided in the image. The file plot1.txt is the blue line with x and y coordinates as presented in the two columns respectively. Then, the second plot which is a polar plot should be placed on top of plot 1 whose data is in plot2.txt. Herein, the first column contains the angles and the second column contains the data with same units as plot 1. Thank you.
  댓글 수: 2
Jaime Abad Arredondo
Jaime Abad Arredondo 2024년 1월 16일
Then it is just a matter of using a hold command to have the two plots together. Importing the data, going from polar to cartesian coordinates and plotting everything together you should get the desired plot...
data_cart=readmatrix('plot1.txt');
data_pol=readmatrix('plot2.txt');
plot(data_cart(:,1),data_cart(:,2),'b')
hold all
plot(data_pol(:,2).*cosd(data_pol(:,1)),data_pol(:,2).*sind(data_pol(:,1)),'r')
Jorge Luis
Jorge Luis 2024년 1월 16일
I used that alternative. I was looking for another option when combining the cartesian plot with the polar plot command in the same graph. Thank you for your response.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Polar Plots에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by