How to change properties of several plots simultaneously?

I want to set properties of several plots all at once instead of setting them individually.
figure(1)
plot(x,y,'--gs','LineWidth',...'MarkerSize',...,'MarkerEdgeColor',...,'MarkerFaceColor',...)
figure(2)
plot(xx,yy,'--gs','LineWidth',...'MarkerSize',...,'MarkerEdgeColor',...,'MarkerFaceColor',...)
figure(3)
plot(xxx,yyy,'--gs','LineWidth',...'MarkerSize',...,'MarkerEdgeColor',...,'MarkerFaceColor',...)
,...
Assuming that properties are the same (linewidth, markersize,...) I want to set them once and not repeat it for each plot.
Thanks in advance

1 件のコメント

dpb
dpb 2020 年 8 月 6 日
編集済み: dpb 2020 年 8 月 6 日
Save the line handles when you plot and use set() See the doc for syntax and examples.
(BTW, the properties don't even have to be the same value...)

サインインしてコメントする。

回答 (1 件)

Steven Lord
Steven Lord 2020 年 8 月 6 日

2 投票

x = 0:360;
y1 = sind(x);
y2 = cosd(x);
figure
h1 = plot(x, y1);
figure
h2 = plot(x, y2);
set([h1, h2], 'Marker', '^', 'LineStyle', '--', 'MarkerIndices', 1:10:numel(x))
Or write a function that accepts x and y data, opens a figure and calls plot with the appropriate properties, then call that function repeatedly with each of your data sets.

7 件のコメント

Zeynab Mousavikhamene
Zeynab Mousavikhamene 2020 年 8 月 6 日
I liked the idea of defining a function for plotting. The problem is that when I want to use hold on to keep the plot on and call the function again to plot on the figure, it does not do that and it plots on a new figure.Any solution?
Steven Lord
Steven Lord 2020 年 8 月 6 日
function h = createplot(x, y)
h = plot(x, y, 'Marker', '^', 'LineStyle', '--', 'MarkerIndices', 1:10:numel(x));
end
Call:
x = 0:360;
y1 = sind(x);
y2 = cosd(x);
createplot(x, y1);
hold on
createplot(x, y2);
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2020 年 8 月 6 日
I did exactly the bove code and instead of plotting in the same axis, the second plot was shown in an other figre.
Walter Roberson
Walter Roberson 2020 年 8 月 6 日
Zeynab: Are you using App Designer ?
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2020 年 8 月 6 日
@Walter Roberson :
No. What is App designer? I write the commands on the matlab script.
Walter Roberson
Walter Roberson 2020 年 8 月 6 日
App Designer is the replacement for GUIDE; it is a UI design tool. It creates a class to hold all of the data. It also uses the new uifigure() and uiaxes() and related objects.
Walter Roberson
Walter Roberson 2020 年 8 月 6 日
MATLAB's idea of what the "current" figure or axes is, can change without warning. Please read https://www.mathworks.com/matlabcentral/answers/?term=tag%3Aalways-parent

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

タグ

質問済み:

2020 年 8 月 5 日

コメント済み:

2020 年 8 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by