celestialgod

plot

Oct 28th, 2015
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.97 KB | None | 0 0
  1. %% data generation
  2. rng(5000);
  3. N_detector = 4;
  4. N_timePoints = 3;
  5. velocity = 30 + randi(40, N_detector, N_timePoints);
  6. distance_detectors = randi(20, N_detector-1, 1);
  7. detector_location = cumsum([0; distance_detectors]);
  8.  
  9. %% first graph - velocity v.s. time
  10. fig = figure;
  11. col = {'b', 'r', 'g', 'c'};
  12. shape = {'d', 's', 'o', 'v'};
  13. legend_num = zeros(N_detector, 1);
  14. for i = 1:N_detector
  15.     for j = 1:N_timePoints
  16.         graph_num = (i-1)*N_detector + j;
  17.         if j == 1
  18.             legend_num(i) = graph_num;
  19.         end
  20.         g(graph_num) = plot(j, velocity(i, j));
  21.         g(graph_num).LineStyle = 'none';
  22.         g(graph_num).Marker = shape{i};
  23.         g(graph_num).MarkerEdgeColor = col{j};
  24.         g(graph_num).MarkerFaceColor = col{j};
  25.         g(graph_num).MarkerSize = 8;
  26.         text(j + 0.1, velocity(i, j), ['\leftarrow v_', num2str(i), '(t_', num2str(j), ')'])
  27.         if i == 1 && j == 1
  28.             hold on;
  29.         end
  30.     end
  31. end
  32. hold off
  33. graph = gca;
  34. graph.XTick = 1:N_timePoints;
  35. graph.XTickLabel = cellstr([repmat('t_', N_timePoints, 1), num2str((1:N_timePoints)')]);
  36. legend(g(legend_num), cellstr([repmat('detector ', N_detector, 1), num2str((1:N_detector)')]), 'Location', 'northwest')
  37. xlim([0.5, N_timePoints + 0.8])
  38. ylim([20, 80])
  39. xlabel('Time')
  40. ylabel('Velocity')
  41. fig.Units = 'centimeters';
  42. fig.PaperPosition = [0,0,15,15];
  43. saveas(gcf, 'graph_20151028/init.png')
  44.  
  45. %% second graph - velocity v.s. location
  46. clear g
  47. fig2 = figure;
  48. legend_num = zeros(N_timePoints, 1);
  49. for i = 1:N_detector
  50.     for j = 1:N_timePoints
  51.         graph_num = (i-1)*N_detector + j;
  52.         if i == 1
  53.             legend_num(j) = graph_num;
  54.         end
  55.         g(graph_num) = plot(detector_location(i), velocity(i, j));
  56.         g(graph_num).LineStyle = 'none';
  57.         g(graph_num).Marker = shape{i};
  58.         g(graph_num).MarkerEdgeColor = col{j};
  59.         g(graph_num).MarkerFaceColor = col{j};
  60.         g(graph_num).MarkerSize = 8;
  61.         text(detector_location(i) + 1, velocity(i, j), ['\leftarrow v_', num2str(i), '(t_', num2str(j), ')'])
  62.         if i == 1 && j == 1
  63.             hold on;
  64.         end
  65.     end
  66. end
  67. hold off
  68. graph = gca;
  69. graph.XTick = detector_location;
  70. graph.XTickLabel = cellstr([repmat('detector ', N_detector, 1), num2str((1:N_detector)')]);
  71. legend(g(legend_num), cellstr([repmat('t_', N_timePoints, 1), num2str((1:N_timePoints)')]), 'Location', 'northwest')
  72. xlimRange = [min(detector_location) - 0.2*range(detector_location), max(detector_location) + 0.3*range(detector_location)];
  73. xlim(xlimRange)
  74. ylim([20, 80])
  75. for i = 1:(N_detector-1)
  76.     loc_text = mean(detector_location(i:i+1));
  77.     text(loc_text, 22, ['l_', num2str(i)])
  78.     text(loc_text-1, 24, ['TT_', num2str(i)])
  79.     text(detector_location(i), 23, '|\leftarrow')
  80.     text(detector_location(i+1)-1.5, 23, '\rightarrow|')
  81. end
  82. xlabel('Locations of Detectors')
  83. ylabel('Velocity')
  84. fig2.Units = 'centimeters';
  85. fig2.PaperPosition = [0,0,15,15];
  86. saveas(gcf, 'graph_20151028/init_2.png')
Advertisement
Add Comment
Please, Sign In to add comment