How to specify Hexadecimal Color Code on a fit line?
Show older comments
I have been able to present a fit line through a scatter plot by writting the following, in a for loop:
t_array: time array
P2P: data array
colour_shape = {'b', 'y' , 'g', 'r'};
for x0 = 1:4
trial2 = colour_shape{x0};
fit_line = fit(t_array, P2P, 'exp2'); %fit function
figure(5)
p(x0) = plot(t_array, P2P, 'o');
hold on
plot(fit_line, trial2)
end
The colours that MATLAB automatically chose for the scatter plot, p(x0) = plot(t_array, P2P, 'o') , are the default ones and are the ideal. I tried using these same default colour for plotting the fit_line, by substituting the colour_shape cell values by:
colour_shape = {'#0072BD' , '#EDB120' , '#77AC30' , '#A2142F'};
But I get the following statement: "Invalid color or line style."
How can I use these colour for the best-fit line? How can I also increase the thickness of these lines?
4 Comments
Rik
on 25 Mar 2022
You can set any RGB triplet as the Color property of a line object. I don't remember whether it should be 0-255 or 0-1, you'll have to look up the documentation for plot or line.
Goncalo Costa
on 25 Mar 2022
Edited: Goncalo Costa
on 25 Mar 2022
Stephen23
on 25 Mar 2022
What do you expect this indexing:
colour_shape{x0}
to achieve on a 1x9 character vector?
Goncalo Costa
on 25 Mar 2022
Accepted Answer
More Answers (1)
This is working in modern Matlab versions:
plot(1:10, rand(1, 10), 'Color', '#A2142F')
For older versions:
color = uint8(sscanf('#A2142F', '#%2x%2x%2x'));
plot(1:10, rand(1, 10), 'Color', color);
Categories
Find more on Color and Styling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
