How to plot two polar graph in same figure window?

4 views (last 30 days)
Amit Kumar
Amit Kumar on 19 Feb 2013
Answered: ag on 26 Sep 2024
Hello, I want to plot two polar graphs on the same window. I used following code: ezpolar('1+cos(t)') hold on ezpolar('1-cos(t)') At the bottom, two names of the figure get overlapped. How to get rid of overlapping figure titles? Also,is there any better alternative way to do this (I'm not a Matlab pro)?

Answers (1)

ag
ag on 26 Sep 2024
Hi Amit,
To plot two polar graphs on the same window without overlapping titles, you can use the polarplot function, which offers more control over the plot appearance compared to ezpolar. Additionally, you can manually manage the legend to prevent overlapping.
The below code demonstrates how to achieve this with explanatory comments:
% Create a new figure
figure;
% Define the parameter t
t = linspace(0, 2*pi, 1000);
% Define the polar functions
r1 = 1 + cos(t);
r2 = 1 - cos(t);
% Plot the first polar graph
polarplot(t, r1, 'DisplayName', '1 + cos(t)');
hold on;
% Plot the second polar graph
polarplot(t, r2, 'DisplayName', '1 - cos(t)');
% Add a legend and position it to avoid overlap
legend('show', 'Location', 'northeastoutside');
% Add a title to the plot
title('Polar Plots of 1 + cos(t) and 1 - cos(t)');
% Customize the grid and appearance
grid on;
hold off;
For more details, please refer to the following MathWorks documentations:
Hope this helps!

Categories

Find more on Polar Plots in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!