Is it possible to color a single number (or a set of numbers) on one of the axes in MATLAB?
Suppose I have a plot:
plot(1:10, rand(1,10))
Now, can I e.g. make the number 3 on the x-axis red?
Unfortunately, you cannot have multiple colors for tick labels in one axes object. However, there's a solution (inspired by this page from MathWorks support site) that achieves the same effect. It overlays the existing axes it with another axes that has only one red tick.
Here's an example:
figure
plot(1:10, rand(1,10))
ax2 = copyobj(gca, gcf); %// Create a copy the axes
set(ax2, 'XTick', 3, 'XColor', 'r', 'Color', 'none') %// Keep only one red tick
ax3 = copyobj(gca, gcf); %// Create another copy
set(ax3, 'XTick', [], 'Color', 'none') %// Keep only the gridline
The result is:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With