Matlab论文插图绘制模板第122期—函数折线图(fplot)

本期分享的是函数折线图的绘制模板。​

所谓函数折线图,就是将自定义线函数进行可视化表达​。

先来看一下成品效果:

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


模板中最关键的部分内容

1. 数据准备

此部分主要是构造函数

% 构造函数fun1 = @(x) sin(1.1*x-pi/5);fun2 = @(x) sin(1.1*x);fun3 = @(x) sin(1.1*x+pi/5);fun4 = @(x) sin(1.1*x+2*pi/5);

2. 颜色定义

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

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

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

C = TheColor('sci',1796);

3. 函数折线图绘制

利用'fplot'命令,绘制初始函数折线图

p1 = fplot(fun1,[-5 5],'LineStyle','-','Marker','v','LineWidth',2,'MarkerFaceColor',C(1,1:3),'Color',C(1,1:3));hold onp2 = fplot(fun2,[-5 5],'LineStyle','-','Marker','o','LineWidth',2,'MarkerFaceColor',C(2,1:3),'Color',C(2,1:3));p3 = fplot(fun3,[-5 5],'LineStyle','-','Marker','^','LineWidth',2,'MarkerFaceColor',C(3,1:3),'Color',C(3,1:3));p4 = fplot(fun4,[-5 5],'LineStyle','-','Marker','s','LineWidth',2,'MarkerFaceColor',C(4,1:3),'Color',C(4,1:3));hTitle = title('Fplot Plot');hXLabel = xlabel('XAxis');hYLabel = ylabel('YAxis');

4. 细节优化

为了插图的美观,对图形细节等进行美化

% 坐标区属性调整set(gca, 'Box', 'off', ...                                % 边框         'LineWidth', 1,...                               % 线宽         'XGrid', 'off', 'YGrid', 'on', ...               % 网格         'TickDir', 'out', 'TickLength', [.01 .01], ...   % 刻度         'XMinorTick', 'off', 'YMinorTick', 'off', ...    % 小刻度         'XColor', [.1 .1 .1],  'YColor', [.1 .1 .1])     % 坐标轴颜色set(gca, 'XLim',[-5.2 5.2],...         'YLim',[-1.1 1.1])% LegendhLegend = legend([p1,p2,p3,p4], ...                 'Samp1', 'Samp2','Samp3','Samp4', ...                 'Location', 'northeast');% Legend位置微调 P = hLegend.Position;hLegend.Position = P + [0.00 0.01 0 0];% 字体和字号set(gca, 'FontName', 'Arial', 'FontSize', 10)set([hLegend, hXLabel, hYLabel], 'FontSize', 11, 'FontName', 'Arial')set(hTitle, 'FontSize', 12, 'FontWeight' , 'bold')% 背景颜色set(gcf,'Color',[1 1 1])% 添加上、右框线xc = get(gca,'XColor');yc = get(gca,'YColor');unit = get(gca,'units');ax = axes( 'Units', unit,...           'Position',get(gca,'Position'),...           'XAxisLocation','top',...           'YAxisLocation','right',...           'Color','none',...           'XColor',xc,...           'YColor',yc);set(ax, 'linewidth',1,...        'XTick', [],...        'YTick', []);

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

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

以上。

相关推荐
玩电脑的辣条哥2 小时前
Python如何播放本地音乐并在web页面播放
开发语言·前端·python
ll7788114 小时前
LeetCode每日精进:20.有效的括号
c语言·开发语言·算法·leetcode·职场和发展
Jackson@ML6 小时前
Python数据可视化简介
开发语言·python·数据可视化
赵琳琅6 小时前
Java语言的云计算
开发语言·后端·golang
lly2024066 小时前
jQuery 杂项方法
开发语言
赵琳琅6 小时前
MDX语言的安全开发
开发语言·后端·golang
开开又心心的学嵌入式7 小时前
C语言——指针进阶应用
c语言·开发语言
开开又心心的学嵌入式7 小时前
C语言——指针基础知识
c语言·开发语言
lonelyhiker7 小时前
javascript的原型链
开发语言·javascript·原型模式
夏梓蕙8 小时前
Elixir语言的软件开发工具
开发语言·后端·golang