I would like to modidy the colors in this 2d plot, different from standard ones (e.g., 'b', 'k')

1 view (last 30 days)
T1 = readtable('variazione.xlsx', 'VariableNamingRule','preserve')
figure
plot(T1.('X'), T1.('S'), '-r',T1.('X_1'), T1.('S_1'), '-b',T1.('X_2'), T1.('S_2'), '-k', 'Linewidth', 1.3)
grid
xlim([-10 10])
ylim([0 25])
set(gca,'xticklabel',num2str(get(gca,'xtick')','%.0f'))
L=legend('E=x MPa','E=y MPa','E=z MPa', 'Location','northwest');
set(L,'Interpreter','latex')
set(gca,'TickLabelInterpreter','latex')
xlabel('$x$ [mm]', 'Interpreter','latex');
ylabel('$\tau$ [Pa]', 'Interpreter','latex');
I would like to choose #D95319 and #A2142F and #77AC30 for the three differend plots

Accepted Answer

Antoni Garcia-Herreros
Antoni Garcia-Herreros on 3 Apr 2023
Hello,
You could separate the plot and specify the colors individually.
D95319=[217,83,25]/255;
A2142=[162, 20, 47]/255;
AC30=[119, 172, 48]/255;
plot(T1.('X'), T1.('S'), 'Color',D95319, 'Linewidth', 1.3)
Unable to resolve the name 'T1.X'.
hold on
plot(T1.('X_1'), T1.('S_1'), 'Color',A2142, 'Linewidth', 1.3)
plot(T1.('X_2'), T1.('S_2'), 'Color',AC30, 'Linewidth', 1.3)
  1 Comment
Dyuman Joshi
Dyuman Joshi on 3 Apr 2023
You can directly use the color code OP mentioned -
x=0:0.01:10;
plot(x, sin(x), 'Color', '#D95319')
hold on
plot(x, cos(x), 'Color', '#A2142F')
plot(x, sin(x).*cos(x), 'Color', "#77AC30")
ylim([-1.75 1.75])
legend({'sin', 'cos', 'sin*cos'})

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 3 Apr 2023
You can define your own colors. For example if you wanted an RGB of 40, 50, 90, you can do
plot(T1.('X'), T1.('S'), '-', 'Color', [40, 50, 90]/255);
or
darkBrown = [120, 50, 20] / 255;
plot(x, y, '-', 'Color', darkBrown);

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!