MATLAB Answers

0

How to change the position of a subplot?

Asked by Robin Spiteri on 18 May 2018

Hi there, I'm trying to use scrollsubplot to allow me display a series of plots that I can scroll through. It works fine, but for some reason I can't seem to change the position details of the subplots, which I'm trying to do to make the elements of each subplot fit better. The first time I try ax.Position=[.55, .2, .4, .7]; it works, but subsequent attempts to try something similar seem to be using the same location as the first. New to Matlab so apologies if this is a silly question, but has anyone managed to modify subplots graphed onto scrollsubplots? thanks very much

      %Create a blank figure
      f = figure;
      f=gcf;
      f.Units='normalized';
      %[left bottom width height]
      f.OuterPosition=[0 0 .88 .45];%is controlling the outer box around the figure
      scrollsubplot(1,2,1)
      ts0 = timeseries(E4_hrX(startIndex:endIndex));
      plot(ts0)
      t = title('Parent Motif (time series per second)', 'FontSize',25);
      ax = gca;%current axis or chart
      ylabel('Heart Rate','FontSize',25)
      xlabel('Time in Seconds','FontSize',25)
      ax.XAxis.FontSize = 17;
      ax.YAxis.FontSize = 25;
      scrollsubplot(1,2,2)
      %display a histogram 
      h = histogram( categorical( emotions{startIndex:endIndex,:} ) )
      t = title('Emotion Distribution', 'FontSize',25);
      text(1:numel(h.Values), h.Values, num2str(h.Values.'), ...
          'HorizontalAlignment', 'Center', 'VerticalAlignment', 'Bottom', 'FontSize',25);
      ax = gca;
      ax.XAxis.FontSize = 17;
      ax.YAxis.FontSize = 25;
      ylabel('Cumulative Observations','FontSize',25)
      %[left bottom width height]
      ax.Position=[.55, .2, .4, .7];%is controlling the outer box around the figure
      row = 2
      for i=1:length(motifIndexAfterThresholds)
          motifs=motifIndexAfterThresholds(i);
          scrollsubplot(1,2,row+1)
          ts0 = timeseries(E4_hrX(motifs:motifs+motifSize),'Name',strcat('BestMotif ', num2str(i), ' '));
          plot(ts0)
          t = title('Child Motif (time series per second)', 'FontSize',26);
          ax = gca;
          %[left bottom width height]
          ylabel('Heart Rate','FontSize',25)
          xlabel('Time in Seconds','FontSize',25)
          ax.XAxis.FontSize = 17;
          ax.YAxis.FontSize = 25;
          row=row+1;
          scrollsubplot(1,2,row+1)
          h = histogram( categorical( emotions{motifIndexAfterThresholds(i):motifIndexAfterThresholds(i)+motifSize,:} ) )
          text(1:numel(h.Values), h.Values, num2str(h.Values.'), ...
          'HorizontalAlignment', 'Center', 'VerticalAlignment', 'Bottom','FontSize',25);
          t = title('Emotion Distribution', 'FontSize',25);
          ax = gca;
          ax.XAxis.FontSize = 17;
          ax.YAxis.FontSize = 25;
          ylabel('Cumulative Observations','FontSize',25)
          %xlabel('Emotions','FontSize',26)
          %[left bottom width height]
          ax.Position=[.55, .2, .4, .7];%is controlling the outer box around the figure
          row=row+1;
      end

  0 Comments

Sign in to comment.

Products


Release

R2018a

0 Answers