meatball1982 发表于 2018-6-1 13:26:30

豆粑粑 matlab XKCD风格的图

XP的论文里,有个comic的图.别人好像是 python,mathematica, latex都画了.matlab 里也有实现, 
https://stackoverflow.com/questions/12701841/xkcd-style-graphs-in-matlab

我自己也玩了一下.效果,还不错.
正常效果的.



comic效果的.



clear all
clc
close all



%# define plot data
x = 1:0.1:10;
y1 = sin(x).*exp(-x/3) + 3;
y2 = 3*exp(-(x-7).^2/2) + 1;



sbp_width=0.7;
sbp_heig=0.6;
n_row = 1;
n_col =1 ;
=fun_mm_subplot_pos(n_row,n_col,sbp_width,sbp_heig);

%# plot
fh = figure('color','w');
set(fh, 'Position', );
ax=axes('position',out_pos(1,:));
hold on
plot(x,y1,'b','lineWidth',5);
% plot(x,y2,'w','lineWidth',9);
plot(x,y2,'r','lineWidth',4);

xlim()
ylim([-1 5])
set(gca,'ytick',[-1:1:5])
set(gca,'fontName','Comic Sans MS','fontSize',20,'lineWidth',3)

%# add an annotation
annotation(fh,'textarrow',,,...
   'string',sprintf('text%shere',char(10)),'headStyle','none','lineWidth',1.5,...
   'fontName','Comic Sans MS','fontSize',20,'verticalAlignment','middle','horizontalAlignment','left')
title('I am title')
xlabel(' I am xlabel')
ylabel(' I am ylabel')
legend({'line1','line2'},'location','southeast','box','off')
grid on
box on

h=gcf;
fi_na = './fig_normal'
fun_work_li_035_myfig_out(h,fi_na,3);



函数
function =fun_mm_xkcd(fh);

%# capture with export_fig
im = export_fig('-nocrop',fh);

% %# add a bit of border to avoid black edges
im = padarray(im,,255);

%# make distortion grid
sfc = size(im);
=ndgrid(1:7:sfc(1),1:7:sfc(2));
pts = ;
tf = cp2tform(pts+1.2*randn(size(pts)),pts,'lwm',14);
w = warning;
warning off images:inv_lwm:cannotEvaluateTransfAtSomeOutputLocations
imt = imtransform(im,tf);
warning(w)
%
% %# remove padding
imt = imt(16:end-15,16:end-15,:);
%
figure('color','w')
imshow(imt)

页: [1]
查看完整版本: 豆粑粑 matlab XKCD风格的图