Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-12-10, 20:48   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 如何可视化显示颜色和值的矩阵?

我想使用MATLAB从双精度矩阵创建这样的图像。

样本图片:

http://twitpic.com/2xs943



回答:

您可以使用内置函数imagesctext并为图形对象调整许多参数,从而轻松地自己创建此类绘图。这是一个例子:

mat = rand(5); % A 5-by-5 matrix of random values from 0 to 1 imagesc(mat); % Create a colored plot of the matrix values colormap(flipud(gray)); % Change the colormap to gray (so higher values are % black and lower values are white) textStrings = num2str(mat(:), '%0.2f'); % Create strings from the matrix values textStrings = strtrim(cellstr(textStrings)); % Remove any space padding [x, y] = meshgrid(1:5); % Create x and y coordinates for the strings hStrings = text(x(:), y(:), textStrings(:), ... % Plot the strings 'HorizontalAlignment', 'center'); midValue = mean(get(gca, 'CLim')); % Get the middle value of the color range textColors = repmat(mat(:) > midValue, 1, 3); % Choose white or black for the % text color of the strings so % they can be easily seen over % the background color set(hStrings, {'Color'}, num2cell(textColors, 2)); % Change the text colors set(gca, 'XTick', 1:5, ... % Change the axes tick marks 'XTickLabel', {'A', 'B', 'C', 'D', 'E'}, ... % and tick labels 'YTick', 1:5, ... 'YTickLabel', {'A', 'B', 'C', 'D', 'E'}, ... 'TickLength', [0 0]); 这是生成的图:



如果您在使用x轴刻度标签时遇到麻烦,则选择太宽且彼此重叠,请按以下方法处理:
  • 较新版本的MATLAB:不确定要添加哪个版本,但是在较新版本中,轴对象现在具有属性 '{X|Y|Z}TickLabelRotation' ,该属性使您可以旋转标签并使它们更好地适合它们。
  • 较旧的MATLAB版本:对于较旧的版本,您可以在MathWorks File Exchange上找到一些可以旋转刻度线标签文本的提交,例如Brian Brian的 XTICKLABEL_ROTATE

更多&回答...
poster 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 04:58


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.