阅读: 2023/3/20 14:46:45
在之前的文章中,分享了很多Matlab折线图的绘制模板:
这些折线图均是在笛卡尔坐标系下绘制的。
那么进一步,再来看一下极坐标折线图的绘制模板。
先来看一下成品效果:
特别提示:本期内容『数据+代码』已上传资源群中,加群的朋友请自行下载。有需要的朋友可以关注同名公号【阿昆的科研日常】,后台回复关键词【绘图桶】查看加入方式。
模板中最关键的部分内容:
1. 数据准备
此部分主要是读取原始数据。
% 读取数据
load data.mat
2. 颜色定义
作图不配色就好比做菜不放盐,总让人感觉少些味道。
但颜色搭配比较考验个人审美,需要多加尝试。
这里直接使用TheColor配色工具中的SCI权威配色库:
%% 颜色定义
C = TheColor('sci',1);
C1 = C(1,:);
C2 = C(2,:);
(点击上图查看TheColor具体功能)
获取方式:公众号(阿昆的科研日常)后台回复 TC
3. 极坐标折线图绘制
使用‘polarplot’命令,绘制初始极坐标折线图。
P1 = polarplot(theta,rho1);
hold on
P2 = polarplot(theta,rho2);
hTitle = title('Plot of Polar Coordinate Defined Function');
4. 细节优化
为了插图的美观,将初始极坐标折线图赋上之前选择的颜色并修改部分线型:
% 定义线宽和颜色(或线型、符号、线宽和颜色)
set(P1, 'LineWidth', 2, 'Color', C1)
set(P2, 'LineWidth', 2, 'Color', C2)
然后,对坐标轴细节等进行美化:
% 坐标区调整
set(gca, 'LineWidth',0.7,... % 线宽
'RGrid','on','ThetaGrid','on',... % 网格
'GridColor',[0 0 0],... % 网格颜色
'ThetaZeroLocation','right',... % 极角0位置
'TickDir', 'out', 'TickLength', [0 0], ... % 刻度
'RMinorTick', 'off', 'ThetaMinorTick', 'off', ... % 小刻度
'ThetaDir', 'clockwise',... % 极角方向 % 边框
'RColor', [0.8 0 0], 'ThetaColor', [0 0 0],... % 极角极径线、字颜色
'RTick',0:0.1:0.6,... % 坐标轴刻度调整
'RLim',[0 0.6],'ThetaLim',[0 360])
% Legend
hLegend = legend([P1,P2], ...
'Samp1', 'Samp2', ...
'Location', 'northeast',...
'orientation','vertical');
P = hLegend.Position;
hLegend.Position = P + [0.1 0.03 0 0];
% 字体和字号
set(gca, 'FontName', 'Arial', 'FontSize', 11)
set(hLegend, 'FontName', 'Arial', 'FontSize', 11)
set(hTitle, 'FontName', 'Arial', 'FontSize', 12, 'FontWeight' , 'bold')
% 背景颜色
set(gcf,'Color',[1 1 1])
设置完毕后,以期刊所需分辨率、格式输出图片。
%% 图片输出
figW = figureWidth;
figH = figureHeight;
set(figureHandle,'PaperUnits',figureUnits);
set(figureHandle,'PaperPosition',[0 0 figW figH]);
fileout = 'test';
print(figureHandle,[fileout,'.png'],'-r300','-dpng');
以上。
转自:“阿昆的科研日常”微信公众号
如有侵权,请联系本站删除!