필터 지우기
필터 지우기

Change active elements of Plot Browser from code

조회 수: 1 (최근 30일)
Julian Braun
Julian Braun 2023년 3월 22일
댓글: Julian 2023년 8월 3일
Hey, I would like to change the active elements of an existing figure with code.
Currently I have to open the Plot Browser and change every element manuelly.
Is there a way to change them with code?

채택된 답변

Yash
Yash 2023년 3월 28일
Hi Julian Braun,
Yes, you can change the active elements of a figure programmatically using MATLAB code. The following code demonstrates how to change the properties of the X-axis and Y-axis labels, the title, and the legend of a figure:
% Create some sample data and plot it
x = 1:10;
y = sin(x);
% Create a figure to visualize your data
% The variable myFig is a handle to your figure.
myFig = figure;
% Plot your data;
p = plot(x, y)
% Get the axis of your plot
ax = p.Parent;
% With the handle to the axis you can change the active elements
% Change the X-axis label
ax.XLabel.String = 'Time (s)'
% Change the Y-axis label
ax.YLabel.String = 'Amplitude'
% Change the title
ax.Title.String = 'Sine Wave'
You can alternatively set the active elements by the below code as well
% Change the X-axis label
xlabel('Time (s)')
% Change the Y-axis label
ylabel('Amplitude')
% Change the title
title('Sine Wave')
% Change the legend
legend('Sine')
You can also access and modify these properties directly using the gca (get current axes) and gcf (get current figure) functions, which return handles to the current axes and figure, respectively. For example, you can change the font size and font weight of the X-axis label like this:
ax = gca;
ax.XLabel.FontSize = 16;
ax.XLabel.FontWeight = 'bold';
You can similarly modify other properties of the axes, such as the tick labels and tick marks, using the XTick, XTickLabel, YTick, and YTickLabel properties of the axes. For more information on customizing plots in MATLAB, see the documentation on graphics customization:
I hope this helps :)

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by