gca method to adjust axes properties not working within function
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello,
I have a function which adjusts some properties of figures after they have been plotted. The function takes the axes graphical object as argument. It goes like this:
function MakeItLookPretty(ax)
ax.YAxis.FontName='Open Sans Bold'
ax.YAxis.FontSize=13
ax.XAxis.TickLength=[0 0]
% and so on...
end
I used to be able to call the function:
axes = gca
MakeItLookPretty(axes)
and it adjusted properties of axes of the current figure. This, however, stopped working since I updated to MATLAB2023b. Calling the function does not throw an error, it seemingly does nothing. Interestingly, if I run the block of code "standalone" (not inside a function) it adjusts the axes perfectly.
What am I missing?
댓글 수: 2
Stephen23
2024년 1월 9일
Do not name your variables "axes".
It works on this forum:
matlabRelease
plot(rand(5,2))
MakeItLookPretty(gca)
function MakeItLookPretty(ax)
ax.YAxis.FontName='Open Sans Bold';
ax.YAxis.FontSize=13;
ax.XAxis.TickLength=[0,0];
% and so on...
end
채택된 답변
Hassaan
2024년 1월 9일
% Call the sample plotting function
createSamplePlot();
% Sample plotting function
function createSamplePlot()
% Create some sample data
x = linspace(0, 2*pi, 100);
y = sin(x);
% Plot the data
plot(x, y);
title('Sample Plot');
% Get the current axes handle
ax = gca;
% Call the custom function to make the plot look pretty
MakeItLookPretty(ax);
end
% Custom function to modify the appearance of the plot
function MakeItLookPretty(ax)
% Modify various properties of the axes
ax.YAxis.FontName = 'Open Sans Bold';
ax.YAxis.FontSize = 13;
ax.XAxis.TickLength = [0 0];
% Add more customization as needed...
end
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Feel free to contact me.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!