# a more detailed example for writing a plotting script #95

Open
opened this Issue Feb 21, 2018 · 2 comments

Projects
None yet
3 participants

### shreyasnarsipur commented Feb 21, 2018

 Under the heading 'Writing MATLAB Scripts', given that we are focusing of software/data carpentry, I feel it is essential we include a more detailed example for plotting data. While the current example takes the user through the very basics of plotting in MATLAB, instructions on how to co-plot data, specify line styles, and basic manipulation of other plotting parameters will be very useful. An example code that can introduce the above mentioned concepts using data from 'inflammation-01.csv' is given below: % script analyze.m patient_data = csvread('inflammation-01.csv'); disp(['Maximum inflammation: ', num2str(max(patient_data(:)))]); disp(['Minimum inflammation: ', num2str(min(patient_data(:)))]); disp(['Standard deviation: ', num2str(std(patient_data(:)))]); ave_inflammation = mean(patient_data, 1); %% Find the number of rows no_of_patients = size(patient_data,1); arr_of_patients = [1:1:no_of_patients]; % This can introduce the concept of building sequential arrays %% Plot % Open figure figure() hold all grid on % Plot data plot(arr_of_patients,ave_inflammation,'-'); plot(arr_of_patients,max(patient_data, [], 1),'--','linewidth',2); plot(arr_of_patients,min(patient_data, [], 1),'-.','color','r'); % Label axis xlabel('Patient Number') ylabel('Degree of Inflammation') % Scale axis set(gca,'xlim',[0 6]) set(gca,'xtick',[0:1:6]) set(gca,'ylim',[0 20]) set(gca,'ytick',[0:4:20]) % Legend plen = legend('Average Inflammation','Max. Inflammation','Min. Inflammation') set(plen,'location','NorthEast') % save plot to disk as png image: print ('patient_data-01','-dpng','-r400') % Example to specify type and quality of image
Member

### shwina commented Mar 10, 2018

 At minimum we will need to include information about what exactly each function in the above script is doing. Without this, both learners and instructors will be confused. I think that this addition would add a lot of (useful, but not essential) detail to the lesson.
Contributor

### gcapes commented May 23, 2018

 I think it would be great to have the axes labelled. There is some of this in later episodes, but I think it would be good to introduce it a bit earlier. Perhaps a little pointer to the documentation could replace some of the more involved formatting suggestions above?

Merged