Adding flair to boring Matlab Axes one plot at a time
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

92 linhas
2.2 KiB

  1. % This file contains a simple Matlab script that demonstrates how to use
  2. % xkcdify.m
  3. %
  4. % The most up to date version of this file can be found at
  5. % https://github.com/slayton/matlab-xkcdify
  6. %
  7. % Copyright(c) 2012, Stuart P. Layton <stuart.layton@gmail.com>
  8. % http://stuartlayton.com
  9. %
  10. % Revision History
  11. % 2012/10/04 - Initial Release
  12. %% - Example 1, XKCDify simple line plots
  13. clear;
  14. clc;
  15. close all;
  16. figure('Position', [100 460 1120 420]);
  17. a(1) = subplot(121); a(2) = subplot(122);
  18. x = 0:.05:2*pi;
  19. y1 = zeros(size(x)); % flat line
  20. y2 = mod(round(x / pi),2)*1.5 - .75; % Square wave
  21. y3 = .2 + .6 * sin(x); % sine wave
  22. plot(x,y1,x,y2,x,y3, 'linewidth', 4, 'Parent', a(1));
  23. plot(x,y1,x,y2,x,y3, 'linewidth', 4, 'Parent', a(2));
  24. set(a, 'XLim', [x(1) - .25, x(end)+.25], 'YLim', [-.9 .9]);
  25. xkcdify(a(2));
  26. %% - Example 2, XKCDify a bar plot with a line plot on top
  27. clear; close all; clc;
  28. figure('Position', [100 460 1120 420]);
  29. a(1) = subplot(121); a(2) = subplot(122);
  30. x = [0:.1:5];
  31. y = 1 + (x-2).^2;
  32. bar([ 3 2 4 6], 'Parent', a(1));
  33. line(x,y,'Color', 'r', 'lineWidth', 3, 'Parent', a(1));
  34. bar([ 3 2 4 6], 'Parent', a(2));
  35. line(x,y,'Color', 'r', 'lineWidth', 3, 'Parent', a(2));
  36. xkcdify(a(2));
  37. set(a, 'XLim', [.5 4.5], 'YLim', [0 7]);
  38. %% - Example 3, XKCDify a boxplot with a line plot on top
  39. clear; close all; clc;
  40. n = 5; data = rand(20,n) * 5;
  41. x = 1:n; y = mean(data) + rand(1,n);
  42. figure('Position', [100 460 1120 420]);
  43. a(1) = subplot(121); a(2) = subplot(122);
  44. boxplot( data, 'Parent', a(1));
  45. set( get(get(a(1), 'Children'),'Children'), 'LineWidth', 3); % Hack to grow the line width of the boxplot
  46. line(x, y, 'color', 'g', 'linewidth', 3, 'Parent', a(1));
  47. boxplot( data, 'Parent', a(2));
  48. set( get(get(a(2), 'Children'),'Children'), 'LineWidth', 3); % Hack to grow the line width of the boxplot
  49. line(x, y, 'color', 'g', 'linewidth', 3, 'Parent', a(2));
  50. xkcdify(gca)
  51. %% - Example 4, XKCDify a subset of axes inside a figure
  52. clear; close all; clc;
  53. figure('Position', [100 460 1120 420]);
  54. x = 0:.1: 2 * pi;
  55. y1 = sin(x);
  56. y2 = cos(x);
  57. for i = 1:3
  58. a(i) = subplot(1,3,i);
  59. plot(x * i, sin(x ./ (i/2)), x*i, cos(x ./ (i/2)), 'Parent', a(i), 'linewidth', 4);
  60. set(a(i), 'XLim', [x(1) - .25, x(end)+.25] * i, 'YLim', [-1.2 1.2]);
  61. end
  62. xkcdify(a(2:3))