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 个评论
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