フィルターのクリア

Changing plot colors directly in .fig files

10 ビュー (過去 30 日間)
Devang Bipinchandra Lad
Devang Bipinchandra Lad 2022 年 5 月 3 日
Suppose if I have a plot saved in a folder. I open It with using openfig command and now want to change the colour of two lines (scatter plot as well as dotted line both want to change to red) present in the plot (image shown below). How can it be done? I m trying findall (which finds there exits two lines) and then try to change the color for on the line but it does not change the color.
The comment lines don't particularly work and offer the error is - "Assigning to 2 elements using a simple assignment statement is not supported. Consider using comma-separated list assignment."- if lineC.Color is directly used.
%% Calling the figure from the folder (numb = 4 represent whole frame)
for i=1:length(percent)
fig_psdm = openfig(strcat(num2str(percent(i)),'_percent\BF_alpha_0\PSDM_plot\PSDM_',num2str(numb),'.fig'),"visible");
name_ax(i) = gca; %saving axis layout of the openfig
% lineC = findall(fig_psdm,'Type','line')
% jj = lineC
% lineC(1,1).Color = 'red'
title(Tit(i)) %title for each subplot or titled
grid off
xlim([0.01 1])
ylim([0.1 10])
subtitle(subt(i)) %subtitle = equation of line
end
hold off
  1 件のコメント
Devang Bipinchandra Lad
Devang Bipinchandra Lad 2022 年 5 月 3 日
It can be done mannually on the figure but I want to change using the MATLAB code.

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

採用された回答

Fangjun Jiang
Fangjun Jiang 2022 年 5 月 3 日
Use findobj() to find the line, set the color to be [Red Green Blue]
>> b=findobj(a,'type','line')
b =
Line with properties:
Color: [0 0.4470 0.7410]
LineStyle: '-'
LineWidth: 0.5000
Marker: 'none'
MarkerSize: 6
MarkerFaceColor: 'none'
XData: [1×100 double]
YData: [1×100 double]
ZData: [1×0 double]
b.Color=[1 0 0]
  4 件のコメント
Fangjun Jiang
Fangjun Jiang 2022 年 5 月 3 日
It looks like you can do this if setting the same color
set(LineC,'Color',[1 0 0])
Devang Bipinchandra Lad
Devang Bipinchandra Lad 2022 年 5 月 3 日
Ok Thanks. Will also keep this in reference.

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

その他の回答 (1 件)

Devang Bipinchandra Lad
Devang Bipinchandra Lad 2022 年 5 月 3 日
for i=1:length(percent)
fig_psdm = openfig(strcat(num2str(percent(i)),'_percent\BF_alpha_0\PSDM_plot\PSDM_',num2str(numb),'.fig'),"visible");
name_ax(i) = gca; %saving axis layout of the openfig
lineC1 = findobj(fig_psdm,'type','line');
lineC1(2).Color = [1 0.5 0.5];
lineC2 = findobj(fig_psdm,'Type','scatter');
lineC2(1).MarkerEdgeColor = [1 0.5 0.5];
% name_ax.LineWidth = 4;
title(Tit(i)) %title for each subplot or titled
grid off
xlim([0.01 1])
ylim([0.1 10])
subtitle(subt(i)) %subtitle = equation of line
end
hold off
This above code finally code for the figure to cahnge the color for both line and scatter plot.

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by