How to customise Polar Plots - Part 2

조회 수: 5 (최근 30일)
Sam Hurrell
Sam Hurrell 2024년 5월 28일
댓글: Sam Hurrell 2024년 6월 1일
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.
Sam Hurrell
Sam Hurrell 2024년 6월 1일
That has solved it, cheers man

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by