Seperating YAxis Ticks/Labels from Axes

조회 수: 6 (최근 30일)
Jordan
Jordan 2025년 2월 6일
댓글: Jordan 2025년 2월 10일
I recently found plotNy, which allows users to have more than two YAxes Ticks/Labels on the same side of the axes (left). This has been useful as in my industry it is often required to view a large number of variables on the same axes component. PlotNy essentially just overlays multiple axes elements and then pulls the lines from the numerous axes components to the last created axes that sits on top of the rest.
I created an app using App Designer and managed to embed the contents of the figure that plotNy generates into a panel within my app. Some re work is required to re-position the axes and Y axis ticks/labels nicely, which I won't show below to keep things concise. When the user adds more variables to the axes, the overall size of the axes is reduced to make space for the additional YAxis Ticks & Labels, which makes good sense. However, because I require a large number of variables to be added to the axes, I end up with a Panel that contains a very small axes component and a large space for all of the required YAxis Ticks/Labels.
My question is, would it be possible to somehow seperate the YAxis Ticks/Labels from the axes itself?
The idea here would be to place the YAxis Ticks/Labels in a seperate, horizontally scrollable panel, that sits directly to the left of the Panel which contains the axes component.
This is how the Axes & YAxis Ticks/Labels look when plotting multiple variables (Screenshot of panel, not whole app)
PlotNy can be found here;
The below code shows how I call PlotNy and send it over to the Panel (app.Panel) within the app.
app.h3i = plotNy(plotData{:}, 'YAxisLabels', legendStrings, 'LineColor', app.linecolors, 'Ylim', app.adjustedYLims);
for i=1:length(app.h3i.ax)
set(app.h3i.ax(i),'ycolor',app.linecolors{i});
end
tempFig = figure('Visible', 'off');
children = app.h3i.parent.Children;
allAxes = [];
for i = 1:length(children)
if isa(children(i), 'matlab.graphics.axis.Axes')
allAxes = [allAxes; children(i)];
end
end
app.newAxes = gobjects(size(allAxes));
for i = 1:length(allAxes)
app.newAxes(i) = copyobj(allAxes(i), tempFig);
end
for i = 1:length(app.newAxes)
app.newAxes(i).Parent = app.Panel;
end
  댓글 수: 2
dpb
dpb 2025년 2월 7일
I hadn't run across <plotNy> before, seems like nice idea,
My idea would be to do two separately but with one with no data but the axes so you can shring its active area to nothing. The other with the data would then make the y-axes labels invisible so you can put the left on top.
I don't know about the panning, though...
Would stackedplot perhaps be a different approach that might suit the application?
Jordan
Jordan 2025년 2월 10일
Yeah it is a nice function that does as it claims. I prefer this over most of the other options available.
Thanks for the input, I'll give this method a try and come back with an update.
As for panning, this was initially a problem but I've since written a small function to adjust the axis values accordingly when zooming/panning etc.
Stackedplot doesn't really work for my case here as I would end up with very thin plots that would somewhat hide the magnitude of any movement in data. Ideally I need all plotted variables to utilise the whole panel.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by