How to plot specified data points on a polar plot with curved lines, instead of straight lines

조회 수: 4 (최근 30일)
Hello,
I am trying to make a polar plot with the following code + data:
c_2 = [780.980150003248 900.818303825083 956.494860478838 855.216748671708 999.328305026861 784.311636929536 806.164595552563]
c_2 = 1×7
780.9802 900.8183 956.4949 855.2167 999.3283 784.3116 806.1646
c_3 = [801.453331427611 896.652257229697 956.494860478838 855.216748671708 985.564716214628 806.880414115856 773.055886925425]
c_3 = 1×7
801.4533 896.6523 956.4949 855.2167 985.5647 806.8804 773.0559
theta = [0 45 63.43494882 90 116.5650512 135.0000394 180];
theta_2 = [180 225 243.43494882 270 296.5650512 315.0000394 360];
polarplot (theta * (pi/180), c_2, '-b', 'Marker','o')
hold on
polarplot (theta_2 * (pi/180), c_3, '-r', 'Marker','x')
What I want is for the connections between the points to be curved, and not straight lines. Any suggestions?
  댓글 수: 2
Dyuman Joshi
Dyuman Joshi 2023년 11월 23일
What should the be the nature of the curve?
Polynomial? Circular? or something else?
Haha Hahaha
Haha Hahaha 2023년 11월 23일
편집: Haha Hahaha 2023년 11월 23일
it should be a similar fit to the attached screenshot, so polynomial i guess. You can also see from the legend that the line fit is a separate object, i.e., it is not a connection between the points but rather a separate graph put together with the points. So this could be one way to go about it, but not sure jow to make such a line fit.

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

답변 (2개)

Chunru
Chunru 2023년 11월 23일
c_2 = [780.980150003248 900.818303825083 956.494860478838 855.216748671708 999.328305026861 784.311636929536 806.164595552563]
c_2 = 1×7
780.9802 900.8183 956.4949 855.2167 999.3283 784.3116 806.1646
c_3 = [801.453331427611 896.652257229697 956.494860478838 855.216748671708 985.564716214628 806.880414115856 773.055886925425]
c_3 = 1×7
801.4533 896.6523 956.4949 855.2167 985.5647 806.8804 773.0559
theta = [0 45 63.43494882 90 116.5650512 135.0000394 180];
theta_2 = [180 225 243.43494882 270 296.5650512 315.0000394 360];
% try interpolation
theta_i = linspace(theta(1), theta(end), 101);
c_2i = interp1(theta, c_2, theta_i);
polarplot (theta * (pi/180), c_2, '-b', 'Marker','o')
hold on
polarplot (theta_i * (pi/180), c_2i, 'k-')
% Do the same for other half
polarplot (theta_2 * (pi/180), c_3, '-r', 'Marker','x')
  댓글 수: 2
Haha Hahaha
Haha Hahaha 2023년 11월 23일
Some Comments:
What is 101 in theta_i?
For the three coordinates near 120 degrees, 90 degrees and 60 degrees, I want the curve to go inwards, and to be a single continuous arc crossing through all three points rather than two arcs. Likewise for 180 degrees, 150 degrees and 120 degrees. Any suggestions?
Chunru
Chunru 2023년 11월 24일
Generate 101 points between the min and max theta. doc linspace for details.
You can try different interpolation methods. doc interp1.
Anyway, if you have two few points and you have to rely on the interpolation methods to guess the points in between and you may not have full control of the curve shape.
c_2 = [780.980150003248 900.818303825083 956.494860478838 855.216748671708 999.328305026861 784.311636929536 806.164595552563];
c_3 = [801.453331427611 896.652257229697 956.494860478838 855.216748671708 985.564716214628 806.880414115856 773.055886925425];
theta = [0 45 63.43494882 90 116.5650512 135.0000394 180];
theta_2 = [180 225 243.43494882 270 296.5650512 315.0000394 360];
% try interpolation
theta_i = linspace(theta(1), theta(end), 101);
c_2i = interp1(theta, c_2, theta_i, 'makima');
polarplot (theta * (pi/180), c_2, '-b', 'Marker','o')
hold on
polarplot (theta_i * (pi/180), c_2i, 'k-')
% Do the same for other half
polarplot (theta_2 * (pi/180), c_3, '-r', 'Marker','x')

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


Star Strider
Star Strider 2023년 11월 24일
I am not certain what result you want. The plot image you posted looks like a sort of spline fit, however when I tried a spline fit, it definitely did not look like the plot image. The only options seem to be the 'pchip' or 'makima' methods.
Try these —
c_2 = [780.980150003248 900.818303825083 956.494860478838 855.216748671708 999.328305026861 784.311636929536 806.164595552563];
c_3 = [801.453331427611 896.652257229697 956.494860478838 855.216748671708 985.564716214628 806.880414115856 773.055886925425];
theta = [0 45 63.43494882 90 116.5650512 135.0000394 180];
theta_2 = [180 225 243.43494882 270 296.5650512 315.0000394 360];
thetai = linspace(theta(1), theta(end));
theta_2i = linspace(theta_2(1), theta_2(end));
c_2i = interp1(theta, c_2, thetai, 'pchip');
c_3i = interp1(theta_2, c_3, theta_2i, 'pchip');
figure
polarplot (deg2rad(theta), c_2, '-b', 'Marker','o', 'DisplayName','c\_2')
hold on
polarplot (deg2rad(thetai), c_2i, '--b', 'DisplayName','Interpolation ‘pchip’: c\_2')
polarplot (deg2rad(theta_2), c_3, '-r', 'Marker','x', 'DisplayName','c\_3')
polarplot(deg2rad(theta_2i), c_3i, '--r', 'DisplayName','Interpolation ‘pchip’: c\_3')
hold off
legend('Location','bestoutside')
c_2i = interp1(theta, c_2, thetai, 'makima');
c_3i = interp1(theta_2, c_3, theta_2i, 'makima');
figure
polarplot (deg2rad(theta), c_2, '-b', 'Marker','o', 'DisplayName','c\_2')
hold on
polarplot (deg2rad(thetai), c_2i, '--b', 'DisplayName','Interpolation ‘makima’: c\_2')
polarplot (deg2rad(theta_2), c_3, '-r', 'Marker','x', 'DisplayName','c\_3')
polarplot(deg2rad(theta_2i), c_3i, '--r', 'DisplayName','Interpolation ‘makima’: c\_3')
hold off
legend('Location','bestoutside')
.

카테고리

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