如何在MATLAB的图中为刻度标签分配多种颜色? [英] How can I assign multiple colors to tick labels in plots in MATLAB?
本文介绍了如何在MATLAB的图中为刻度标签分配多种颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在MATLAB中的一个轴上为单个数字(或一组数字)着色?
Is it possible to color a single number (or a set of numbers) on one of the axes in MATLAB?
假设我有一个情节:
plot(1:10, rand(1,10))
现在,例如将x轴上的数字3设为红色?
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.
这是一个例子:
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
结果是:
这篇关于如何在MATLAB的图中为刻度标签分配多种颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文