Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I see two ways to solve this: The first way is to add some jitter to the x/y coordinates of the plot features. This has the advantage that you can easily modify a plot, but you have to draw the axes yourself if you want to have them xkcdyfied (see <a href="https://stackoverflow.com/a/12711092/232610">@Rody Oldenhuis' solution</a>). The second way is to create a non-jittery plot, and use <code>imtransform</code> to apply a random distortion to the image. This has the advantage that you can use it with any plot, but you will end up with an image, not an editable plot.</p> <p>I'll show #2 first, and my attempt at #1 below (if you like #1 better, look at <a href="https://stackoverflow.com/a/12711092/232610">Rody's solution</a>!).</p> <p><img src="https://i.stack.imgur.com/s6hts.png" alt="enter image description here"></p> <p>This solution relies on two key functions: <a href="http://www.mathworks.com/matlabcentral/fileexchange/23629" rel="noreferrer">EXPORT_FIG</a> from the file exchange to get an anti-aliased screenshot, and <a href="http://www.mathworks.com/help/images/ref/imtransform.html" rel="noreferrer">IMTRANSFORM</a> to get a transformation.</p> <pre><code>%# define plot data x = 1:0.1:10; y1 = sin(x).*exp(-x/3) + 3; y2 = 3*exp(-(x-7).^2/2) + 1; %# plot fh = figure('color','w'); hold on plot(x,y1,'b','lineWidth',3); plot(x,y2,'w','lineWidth',7); plot(x,y2,'r','lineWidth',3); xlim([0.95 10]) ylim([0 5]) set(gca,'fontName','Comic Sans MS','fontSize',18,'lineWidth',3,'box','off') %# add an annotation annotation(fh,'textarrow',[0.4 0.55],[0.8 0.65],... 'string',sprintf('text%shere',char(10)),'headStyle','none','lineWidth',1.5,... 'fontName','Comic Sans MS','fontSize',14,'verticalAlignment','middle','horizontalAlignment','left') %# capture with export_fig im = export_fig('-nocrop',fh); %# add a bit of border to avoid black edges im = padarray(im,[15 15 0],255); %# make distortion grid sfc = size(im); [yy,xx]=ndgrid(1:7:sfc(1),1:7:sfc(2)); pts = [xx(:),yy(:)]; tf = cp2tform(pts+randn(size(pts)),pts,'lwm',12); 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) </code></pre> <hr> <p>Here's my initial attempt at jittering</p> <p><img src="https://i.stack.imgur.com/tFnPs.png" alt="enter image description here"></p> <pre><code>%# define plot data x = 1:0.1:10; y1 = sin(x).*exp(-x/3) + 3; y2 = 3*exp(-(x-7).^2/2) + 1; %# jitter x = x+randn(size(x))*0.01; y1 = y1+randn(size(x))*0.01; y2 = y2+randn(size(x))*0.01; %# plot figure('color','w') hold on plot(x,y1,'b','lineWidth',3); plot(x,y2,'w','lineWidth',7); plot(x,y2,'r','lineWidth',3); xlim([0.95 10]) ylim([0 5]) set(gca,'fontName','Comic Sans MS','fontSize',18,'lineWidth',3,'box','off') </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload