How to change color of berfit curve

9 次查看(过去 30 天)
How do I change the color of a berfit plot? I have two fits that I am plotting on the same graph, and I would like to change the symbol color/shape and line color. I have tried the standard plot color formatting and it hasn't worked and can't find a solution anywhere. I have two arrays of random data to show you the structure of my code:
Temp_x = [
9
8
7
6
5
4
3
];
Temp_y = [
1e-3
5e-3
1e-2
2e-2
3e-2
5e-2
1e-1
];
Temp_y2 = [
2e-3
6e-3
2e-2
3e-2
4e-2
6e-2
1.1e-1
];
figure;
berfit(fliplr(Temp_x'),fliplr(Temp_y')); %transpose and flip data so it would be in the right order for berfit
hold on;
berfit(fliplr(Temp_x'),fliplr(Temp_y2'))
legend('Tempy','Curve Fit', 'Tempy2', 'Curve Fit')
title('Temp Title')
subtitle('Temp Subtitle')
axis([1 15 1e-4 .1])
hold off;
The plot shows this:

采纳的回答

Voss
Voss 2024-5-23
Temp_x = [
9
8
7
6
5
4
3
];
Temp_y = [
1e-3
5e-3
1e-2
2e-2
3e-2
5e-2
1e-1
];
Temp_y2 = [
2e-3
6e-3
2e-2
3e-2
4e-2
6e-2
1.1e-1
];
figure;
berfit(fliplr(Temp_x'),fliplr(Temp_y')) %transpose and flip data so it would be in the right order for berfit
hold on;
berfit(fliplr(Temp_x'),fliplr(Temp_y2'))
legend('Tempy','Curve Fit', 'Tempy2', 'Curve Fit')
title('Temp Title')
subtitle('Temp Subtitle')
axis([1 15 1e-4 .1])
hold off;
Get the plotted lines:
h = findobj(gcf,'Type','line')
h =
4x1 Line array: Line (Curve Fit) Line (Tempy2) Line (Curve Fit) Line (Tempy)
Set their colors:
h(1).Color = 'b';
h(2).Color = 'r';
h(3).Color = 'k';
h(4).Color = [0 0.6 0];

更多回答(1 个)

Les Beckham
Les Beckham 2024-5-23
You can capture the fit data from berfit and use the normal plot command to plot the data with full control over the symbols, lines, and colors.
Temp_x = [
9
8
7
6
5
4
3
];
Temp_y = [
1e-3
5e-3
1e-2
2e-2
3e-2
5e-2
1e-1
];
Temp_y2 = [
2e-3
6e-3
2e-2
3e-2
4e-2
6e-2
1.1e-1
];
figure;
Temp_x = fliplr(Temp_x'); %transpose and flip data so it would be in the right order for berfit
Temp_y = fliplr(Temp_y');
Temp_y2 = fliplr(Temp_y2');
ber1 = berfit(Temp_x, Temp_y)
ber1 = 1x7
0.1000 0.0500 0.0305 0.0189 0.0106 0.0049 0.0010
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ber2 = berfit(Temp_x, Temp_y2);
hp = plot(Temp_x, Temp_y, 'bx', Temp_x, ber1, 'b-', Temp_x, Temp_y2, 'rx', Temp_x, ber2, 'r-');
set(gca, 'YScale', 'log')
grid on
legend('Tempy','Curve Fit', 'Tempy2', 'Curve Fit')
title('Temp Title')
subtitle('Temp Subtitle')
axis([1 15 1e-4 .1])

类别

Help CenterFile Exchange 中查找有关 Test and Measurement 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by