How to customise Polar Plots - Part 2

8 次查看(过去 30 天)
Following on from a question I had a year ago (How to customise Polar Plots - MATLAB Answers - MATLAB Central (mathworks.com)), I am in need of shifting the location of the chart/axis titles. My polar plot has a range of 180^o: from-90 to 90 with 0 at the middle bottom, but because I've had to increase the axis fontweight to bold, the Raxis values and label overlap with the chart title. When I try to relocate the chart title horizontally to the left, it is going off the screen. Can someone advise, I've included the relevant code below:
polarplot(th2-pi/2,Rs); Ax = gca; Ax.ThetaZeroLocation = 'bottom'; Ax.ThetaLim = [270 360+90];
Ax.LineWidth = 2; Ax.FontSize = 16; Ax.FontWeight = 'bold'; Ax.RLim = [0 1e-7]; Ax.ThetaTick = Ax.ThetaLim(1):10:Ax.ThetaLim(2);
Ax.RTick = Ax.RLim(1):1e-8:Ax.RLim(2); Ax.ThetaTickLabel = compose('%d',-90:10:90);
title('I want this chart title to be wholly visible in the top-left hand corner of the screen','FontSize',20,'FontWeight','bold');

采纳的回答

Adam Danz
Adam Danz 2024-5-28
编辑:Adam Danz 2024-5-30
Thanks for sharing this, @Sam Hurrell. Something's fishy.
Here's a workaround. You can set the axes' TitleHorizontalAlignment property to left and the title's VerticalAlignment property to Top.
polarplot(rand(1,10),rand(1,10));
Ax = gca;
Ax.ThetaZeroLocation = 'bottom';
Ax.ThetaLim = [270 360+90];
Ax.LineWidth = 2;
Ax.FontSize = 16;
Ax.FontWeight = 'bold';
Ax.RLim = [0 1e-7];
Ax.ThetaTick = Ax.ThetaLim(1):10:Ax.ThetaLim(2);
Ax.RTick = Ax.RLim(1):1e-8:Ax.RLim(2);
Ax.ThetaTickLabel = compose('%d',-90:10:90);
% Workaround:
t = title('Title','FontSize',20,'FontWeight','bold');
Ax.TitleHorizontalAlignment = 'Left';
t.VerticalAlignment = 'top';
Alternatively, use tiledlayout
Tiledlayout uses a different space management system. This demo manually inserts newline characters to break up the long title.
figure('position',[50 50 600 600])
tiledlayout(1,1,'padding','compact')
Ax = nexttile();
polarplot(rand(1,10),rand(1,10));
Ax = gca;
Ax.ThetaZeroLocation = 'bottom';
Ax.ThetaLim = [270 360+90];
Ax.LineWidth = 2;
Ax.FontSize = 16;
Ax.FontWeight = 'bold';
Ax.RLim = [0 1e-7];
Ax.ThetaTick = Ax.ThetaLim(1):10:Ax.ThetaLim(2);
Ax.RTick = Ax.RLim(1):1e-8:Ax.RLim(2);
Ax.ThetaTickLabel = compose('%d',-90:10:90);
% Workaround:
str = ['I want this',newline(),...
'chart title to',newline(),...
'be wholly visible',newline(),...
'in the top-left',newline(),...
'hand corner of',newline(),...
'the screen'];
t = title(str,'FontSize',20,'FontWeight','bold');
Ax.TitleHorizontalAlignment = 'Left';
t.VerticalAlignment = 'middle';
t.HorizontalAlignment = 'left';
  3 个评论
Adam Danz
Adam Danz 2024-5-29
编辑:Adam Danz 2024-5-30
Try putting it in a tiled layout. I've updated my answer to show how.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Polar Plots 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by