Matlab论文插图绘制模板第85期—模值赋色的箭头图

news/2024/9/23 4:35:56/

在之前的文章中,分享了Matlab箭头图的绘制模板:

进一步,如果我们想对每一个箭头赋上颜色,以更加直观地表示其模值的大小,该怎么操作呢?

那么,来看一下模值赋色的箭头图的绘制模板。

先来看一下成品效果:

特别提示:本期内容『数据+代码』已上传资源群中,加群的朋友请自行下载。有需要的朋友可以关注同名公号【阿昆的科研日常】,后台回复关键词【绘图桶】查看加入方式


模板中最关键的部分内容

1. 数据准备

此部分主要是读取原始数据

% 读取数据load data.mat

2. 颜色定义

作图不配色就好比做菜不放盐,总让人感觉少些味道。

但颜色搭配比较考验个人审美,需要多加尝试。

这里直接使用TheColor配色工具中的SCI权威配色库

%% 颜色定义map = TheColor('sci',2068);% map = flipud(map);

3. 模值赋色的箭头图绘制

使用‘quiver’命令,绘制初始箭头图

q = quiver(X,Y,U,V);hTitle = title('Visualization of air flow data over North America');hXLabel = xlabel('xaxis');hYLabel = ylabel('yaxis');

4. 细节优化

利用ColortheArrow函数(Suever),将初始箭头图赋上之前选择的颜色并对线型进行调整

% 赋色ColortheArrow(q,map)colorbar% 线型调整q.LineWidth = 1;q.ShowArrowHead = 'on';

然后,对坐标轴细节等进行美化:

% 坐标区调整axis tightset(gca, 'Box', 'off', ...                                   % 边框         'LineWidth', 1,...                                  % 线宽         'XGrid', 'off', 'YGrid', 'off', ...                 % 网格         'TickDir', 'out', 'TickLength', [.01 .01], ...      % 刻度         'XMinorTick', 'off', 'YMinorTick', 'off', ...       % 小刻度         'XColor', [.1 .1 .1],  'YColor', [.1 .1 .1])        % 坐标轴颜色% 字体和字号set(gca, 'FontName', 'Arial', 'FontSize', 10)set([hXLabel, hYLabel], 'FontSize', 11, 'FontName', 'Arial')set(hTitle, 'FontSize', 12, 'FontWeight' , 'bold')% 背景颜色set(gcf,'Color',[1 1 1])% 添加上、右框线hold onXL = get(gca,'xlim'); XR = XL(2);YL = get(gca,'ylim'); YT = YL(2);xc = get(gca,'XColor');yc = get(gca,'YColor');plot(XL,YT*ones(size(XL)),'color', xc,'linewidth',1)plot(XR*ones(size(YL)),YL,'color', yc,'linewidth',1)

设置完毕后,以期刊所需分辨率、格式输出图片。

%% 图片输出figW = figureWidth;figH = figureHeight;set(figureHandle,'PaperUnits',figureUnits);set(figureHandle,'PaperPosition',[0 0 figW figH]);fileout = 'test';print(figureHandle,[fileout,'.png'],'-r300','-dpng');

ColortheArrow函数

function ColortheArrow(q,map)% author Suever%// Compute the magnitude of the vectorsmags = sqrt(sum(cat(2, q.UData(:), q.VData(:),reshape(q.WData, numel(q.UData), [])).^2, 2));%// Get the current colormapcurrentColormap = colormap(map);%// Now determine the color to make each arrow using a colormap[~, ~, ind] = histcounts(mags, size(currentColormap, 1));% clims = num2cell(get(gca, 'clim'));% [~, ~, ind] = histcounts(mags, linspace(clims{:}, size(currentColormap, 1)));%// Now map this to a colormap to get RGBcmap = uint8(ind2rgb(ind(:), currentColormap) * 255);cmap(:,:,4) = 255;cmap = permute(repmat(cmap, [1 3 1]), [2 1 3]);%// We repeat each color 3 times (using 1:3 below) because each arrow has 3 verticesset(q.Head,'ColorBinding', 'interpolated','ColorData', reshape(cmap(1:3,:,:), [], 4).'); %'%// We repeat each color 2 times (using 1:2 below) because each tail has 2 verticesset(q.Tail,'ColorBinding', 'interpolated','ColorData', reshape(cmap(1:2,:,:), [], 4).');end

以上。


http://www.ppmy.cn/news/43028.html

相关文章

EightCap易汇:外汇投资入门需要了解哪些必要知识?

外汇市场是国际投资市场,日内交易量巨大,盈利机会极多。外汇是一种含有杠杆的投资产品,杠杆带来了高收益,也会带来高风险,对于外汇新手来说存在一定难度。新手投资者要如何交易,才能抓住外汇市场的盈利机会…

山东双软认证需要什么条件

山东双软认证需要什么条件 ​ 一、软件企业认定服务 1.软件企业认定基本条件 ①在我国境内成立,有固定办公场所,以软件开发销售为主营业务的企业; ②大专学历人数≧当年月平均人数的40%,研发人员≧当年月平均人数20%&#xff1b…

由libunifex来看Executor的任务构建

前言 之前的一篇文章讲述了future的优缺点,以及future的组合性,其中也讲述了构建任务DAG一些问题,同时给出了比较好的方案则是Executor。 Executor还未进入标准(C23),Executor拥有惰性构建及良好的抽象模型…

登录界面到个人中心

登录页面: 1. 使用路由渲染登录组件 在 /src/views 目录之下,创建 Login 文件夹,并在其下新建 Login.vue登录组件 在 /src/router/index.js 路由模块中,导入需要通过路由渲染的 login.vue 登录组件 在路由模块的 routes 数组中…

c++11 标准模板(STL)(std::unordered_multimap)(十三)

定义于头文件 <unordered_map> template< class Key, class T, class Hash std::hash<Key>, class KeyEqual std::equal_to<Key>, class Allocator std::allocator< std::pair<const Key, T> > > class unordered…

图像分割中的混淆矩阵和利用混淆矩阵计算指标

目录 1. 介绍 2. 创建混淆矩阵 2.1 update 方法 2.2 compute 方法 2.3 str 方法 3. 测试 4. 完整代码 1. 介绍 语义分割中&#xff0c;性能指标可以利用混淆矩阵进行计算 这里实现的方法和图像分类中不一样&#xff0c;需要的可以参考&#xff1a;混淆矩阵Confusion M…

springboot+jwt令牌简单登录案例

1. 什么是JWT&#xff1f;JSON Web Token JSON Web Token (JWT)是⼀个开放标准(RFC 7519)&#xff0c;它定义了⼀种紧凑的、⾃包含的⽅式&#xff0c;⽤于 作为JSON对象在各⽅之间安全地传输信息。该信息可以被验证和信任&#xff0c;因为它是数字签名的。 1.1 什么时候应该⽤…

webgl-画一个彩色矩形

html <!DOCTYPE html> <head> <style> *{ margin: 0px; padding: 0px; } </style> </head> <body> <canvas id webgl> 您的浏览器不支持HTML5,请更换浏览器 </canvas> <script src"./main.js"></script&g…