Axes are a different colour from lines plotted using the same Hex values
47 views (last 30 days)
Show older comments
I'm trying to work out why axes plot in a different colour from lines even though I've specified both to be the same Hex values.
In the example I've set up two y axes, one on the left and one on the right, to illustrate my point, along with data for each axis.
I've set the same Hex value pair for the data as for the axes. One is a dark blue and one is a dark red.
Yet when the plot is drawn, the axes are notable lighter in colour than the lines - see inserted image/attachment.
The 'correct' hex value colour is only reproduced in the line - the axes are a lighter colour than they should be.
Is there any way to fix this, as I'd like the line and the axes to match entirely?
figure
yyaxis left
plot((5:15), sin((5:15)/5), 'Linewidth', 2, 'color', [0.2627 0.3882 0.8471]) % blue hex
yyaxis right
plot((5:15), sinh((5:15)/5), 'Linewidth', 2, 'color', [0.9020 0.0980 0.2941]) % red hex
ax = gca; ax.FontSize = 16;
ax.YAxis(1).Color = [0.2627 0.3882 0.8471]; % same blue hex
ax.YAxis(2).Color = [0.9020 0.0980 0.2941]; % same red hex

Many thanks.
0 Comments
Answers (1)
dpb
on 8 Jan 2026 at 14:16
Edited: dpb
on 8 Jan 2026 at 15:38
figure
yyaxis left
plot((5:15), sin((5:15)/5), 'Linewidth', 2, 'color', [0.2627 0.3882 0.8471]) % blue hex
yyaxis right
plot((5:15), sinh((5:15)/5), 'Linewidth', 2, 'color', [0.9020 0.0980 0.2941]) % red hex
ax = gca; ax.FontSize = 16;
ax.YAxis(1).Color = [0.2627 0.3882 0.8471]; % same blue hex
ax.YAxis(2).Color = [0.9020 0.0980 0.2941]; % same red hex
ax.YAxis(1).LineWidth=1; ax.YAxis(1).TickLabelFormat='%0.1f';
ax.YAxis(2).LineWidth=2; ax.YAxis(2).TickLabelFormat='%2d';
The issue is not that the color is different, only that the visual appearance is that it is lighter because it is not as heavy of a line as the plotted lines. The default unless overridden is 0.5.
To illustrate difference, the above used 1 and 2 for the left and right axes; choose what better pleases your tastes.
The above also fixes up the ugly mismatch of the LH axis not being same decimal precision owing to the defatult '%g' formatting; unfortunately, even setting a field width for the RH axis doesn't really solve the alignment issue with a proportional font as the leading space isn't as wide as the digits are.
Note changing the LineWidth also has the effect of boldening the tick labels.
2 Comments
See Also
Categories
Find more on Axis Labels 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!