Stacked Plots - Changing the Location and Oreintation of the Display Labels (Y Labels)

조회 수: 19 (최근 30일)
Currently working on a project implementing stacked plots to display information inside of a tiled layout figure.
The image below, figure 1, is a older version that I want to update. I would like to highlight the Title for each line plotted in the graph is displayed on the right hand side. (I Correlator, Q Correlator, ... etc)
Figure (1)
The image below, figure 2, is the version I am currently working with. I want to immitate this way of displaying Display Labels on the right hand side.
Figure (2)
Some noticeable differences between the two versions is the use of tiled layout and the stacked plot. In this case, tiled layout creates a 2x2 seperation of the figure. This stacked plot is taking up tiles 2 and 4, using the call nexttile(t, 2, [2 1]);
How can I alter the position of the s.DisplayLabels so that they appear on the right hand side like the first figure? Or atleast rotate the labels such that they are vertical rather than horizontal?
Here is some sample code:
%% Creating demo lines to graph (y1 and y2)
x = 1:0.1:10;
y1 = sin(x);
y2 = cos(x);
tbl = table(y1', y2'); % Table to pass into the stackedplot
%% Creating the plotting figure
f = figure();
% Using tiledlayout
t = tiledlayout(f, 2, 1, "TileSpacing","compact");
nexttile(t, [2, 1]);
s = stackedplot(tbl); % Implementation of stacked plots
s.DisplayLabels = ["Line 1", "Line 2"]; % Displaying the Y Labels / Display Labels
s.LineWidth = 1.5;
s.GridVisible = "on";
s.Title = "My Graph";

답변 (1개)

Adam Danz
Adam Danz 2024년 2월 17일
Y-axis label rotation in stackedplot is addressed here.
You could use the same approach to change the YAxisLocation to the right but this will also change the location of the y-axis ticks. How did you acheive this in the older version that shows the labels on the right and what is preventing you from doing that again?
  댓글 수: 1
Christopher Kong
Christopher Kong 2024년 2월 19일
The older version created a series of axes structures to create the similar visual, then changed the title of the axes to be the appropiate Y-axis label. Then the Position of the title was manually changed such that it would be on the right.
hPlot(1) = axes('Position',[0.4 0.875 0.50 0.10],'FontSize',8); %I
plot (hPlot(1), timeAxisInSeconds, ...
trackResults(channelNr).I_P, 'Color',[0.21 0.31 0.46]);
title ('Parent',hPlot(1), ['I',newLn, 'Correlator'],...
'Units','normalized','Position',[1.1 0.4]);
Trying to do something similar, I first did the following line to access the axes node children.
s = stackedplot(tbl);
ax = findobj(s.NodeChildren, 'Type','Axes');
However, due to the uicontrol implementation and the nature of the plotting I am trying to do. The following error occurs.
get([ax.YLabel], 'Position')
set([ax.YLabel], 'Position',[1.1 0.4])
Error using matlab.graphics.primitive.Text/get
Canvas update iteration limit exceeded. This can occur if the scene is marked dirty during a drawnow.
Error in plotTracking (line 202)
get([ax.YLabel], 'Position')
In this way, I am not able to grab the position of the Y Labels and change the horizontal position. Additionally, based on the code given in a previous answer. The Y Labels orientation versus Display Labels do not seem to agree.
%% Creating demo lines to graph (y1 and y2)
x = 1:0.1:10;
y1 = sin(x);
y2 = cos(x);
tbl = table(y1', y2'); % Table to pass into the stackedplot
%% Creating the plotting figure
f = figure();
% Using tiledlayout
t = tiledlayout(f, 2, 1, "TileSpacing","compact");
nexttile(t, [2, 1]);
s = stackedplot(tbl); % Implementation of stacked plots
s.DisplayLabels = ["Line 1", "Line 2"]; % Displaying the Y Labels / Display Labels
s.LineWidth = 1.5;
s.GridVisible = "on";
s.Title = "My Graph";
ax = findobj(s.NodeChildren, 'Type','Axes');
set([ax.YLabel],'Rotation',90,'HorizontalAlignment', 'Center', 'VerticalAlignment', 'Bottom')

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

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by