MATLAB plot Tiny Tricks — by Optic_css
Use set(gca, ·, ·, ·, ···) HANDLE for editing
[纪录] 这里是我常常应用的MATLAB制图Code,记录下来是为了当前更快地实现一些根本的制图Setting类的操作,换句话说,当作查阅的备用叭… …
上面所展现的Codes是一些根本的绘图Setting,很容易能看懂,根本蕴含了对于一张图像
‘colormap’
‘grid’
‘box’
‘xtick’、’ytick’、’LinwWidth’、’FontName’、’Color’
‘xlabel’、’ylabel’、’title’、’legend’
‘axis’
的设置,这样曾经算是根本满足了需要… …
% Close all image windows
close all;
%———————————————————————————————————————————————————
%|···········Plotting/Facing Codes Here············|
%———————————————————————————————————————————————————
% Retain control of the current diagram window
hold on;
% 逆転/バック・キック colormap
colormap(flipud(othercolor('Spectral9')));
% colormap(othercolor('Spectral9'));
% Add a plaid shading
grid on;
% Remove the outer frame of the drawing window
box off;
%———————————————————————————————————————————————————
%|·········Use set(·) to Change the style··········|
%———————————————————————————————————————————————————
% set(gca,'xticklabel',roundn((50:50:500)*deltal,-1));
set(gca,'xtick',20:20:180);
% set(gca,'yticklabel',roundn((50:50:500)*deltal,-1));
% set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.12f'));
set(gca,'ytick',50:50:500);
set(gca,'Linewidth',1.5);
set(gca,'FontName','Times New Roman');
set(gca,'Color',[1.000000000000000 0.388235294117647 0.278431372549020]);
%———————————————————————————————————————————————————
%|·················set the labels··················|
%———————————————————————————————————————————————————
xlabel('\xi');
ylabel('\xi');
title('\xi');
legend('相邻方向差分值','FontName','微软雅黑');
%———————————————————————————————————————————————————
%|······Axis setting, use the handle axis(·)·······|
%———————————————————————————————————————————————————
axis([0 5400 30 80]);
legend(['$\bar{x}(\lambda)$';'$\bar{y}(\lambda)$';'$\bar{z}(\lambda)$'],'interpreter','latex');
上面则是一个小trick,对于如何将图窗background变通明的Setting办法,次要是前面对于’InvertHardCopy’的setting,这是属于某个凶恶分享者的资源,
%———————————————————————————————————————————————————
%|·····················Trans·······················|
%———————————————————————————————————————————————————
% If you ever wondered this: which is particularly useful when you export it to formats that feature transparency, like eps, gif, png, ...
% you created a figure and guess the configuration as below:
set(gcf,'color','none');
set(gca,'color','none');
% but this following little detail took me ages to figure out
set(gcf,'InvertHardCopy','off');
A useful (MAYBE) HEX-RGB to String convertor
上面是一个将hexadecimal RGB色调代号转换为MATLAB实用的色调值,也即
输出一个$\rm string:\ ”ff 63 47”/”ff-63-47”$
输入一组向量
$\rm col=1\times3$
$1.000000000000000\ \ \ 0.388235294117647\ \ \ 0.278431372549020$
设计中采纳inline function $\rm hexstr(·)$,做成了一个vector函数的格局,当需要很大的时候,可能显著减小calling所带来的耗费,
col = hex2nstr(["ff 63 47","2e 8b 57","6a 5a cd"]);
%————————————————————————————————————————————————————————————
%|··by Optic_css, the nStr(·) can help you get the [1,1,1]··|
%————————————————————————————————————————————————————————————
function nStr = hex2nstr(hexstr)
% Function that helos to get the normalized str used in MATLAB color spaces
nStr = [];
for io = 1:length(hexstr)
% Splitor to get the divided types, "ff 0a 89"/"ff-0a-89" -> "ff","oa","89"
splitor = strsplit(hexstr(io), '["-", ]',"DelimiterType","RegularExpression");
% Divide the splitor into 3 pieces
dec_ = cell2mat(splitor(1,1));
dec__ = cell2mat(splitor(1,2));
dec___ = cell2mat(splitor(1,3));
% Divided by 255: "ff", and take string addtion
nStr = [nStr;[hex2dec(dec_)/255 hex2dec(dec__)/255 hex2dec(dec___)/255]];
end
end