How to customise Polar Plots - Part 2

3 visualizzazioni (ultimi 30 giorni)
Sam Hurrell
Sam Hurrell il 28 Mag 2024
Commentato: Sam Hurrell il 1 Giu 2024
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');

Risposta accettata

Adam Danz
Adam Danz il 28 Mag 2024
Modificato: Adam Danz il 30 Mag 2024
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 Commenti
Adam Danz
Adam Danz il 29 Mag 2024
Modificato: Adam Danz il 30 Mag 2024
Try putting it in a tiled layout. I've updated my answer to show how.
Sam Hurrell
Sam Hurrell il 1 Giu 2024
That has solved it, cheers man

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by