summaryrefslogtreecommitdiff
path: root/Tutorial02-Plots/Scilab_code
diff options
context:
space:
mode:
Diffstat (limited to 'Tutorial02-Plots/Scilab_code')
-rw-r--r--Tutorial02-Plots/Scilab_code/README.md1
-rw-r--r--Tutorial02-Plots/Scilab_code/Tutorial2_semilog.sce28
-rw-r--r--Tutorial02-Plots/Scilab_code/Tutotial2_multi_plotting.sce38
-rw-r--r--Tutorial02-Plots/Scilab_code/Tutotial2_plot_save.sce32
-rw-r--r--Tutorial02-Plots/Scilab_code/Tutotial2_plot_save_func.sce27
-rw-r--r--Tutorial02-Plots/Scilab_code/Tutotial2_plotting.sce16
-rw-r--r--Tutorial02-Plots/Scilab_code/change_plot_attribs.sci10
7 files changed, 152 insertions, 0 deletions
diff --git a/Tutorial02-Plots/Scilab_code/README.md b/Tutorial02-Plots/Scilab_code/README.md
new file mode 100644
index 0000000..150fc44
--- /dev/null
+++ b/Tutorial02-Plots/Scilab_code/README.md
@@ -0,0 +1 @@
+# Scilab code for scientific plotting
diff --git a/Tutorial02-Plots/Scilab_code/Tutorial2_semilog.sce b/Tutorial02-Plots/Scilab_code/Tutorial2_semilog.sce
new file mode 100644
index 0000000..9acc3a6
--- /dev/null
+++ b/Tutorial02-Plots/Scilab_code/Tutorial2_semilog.sce
@@ -0,0 +1,28 @@
+//This script demonstrate multi-plotting in Scilab
+clear
+clc
+exec change_plot_attribs.sci;
+
+//Import data from file
+Data = csvRead('/home/chayan/Documents/scilab-tutorials/Tutorial2_Plot/Data/Tut2_data1.csv');
+
+//Segregate the data into variables
+y = Data(:,1);
+x = [Data(:,4) Data(:,5)]
+
+//Style of plot
+style_plot = [1,2]
+
+//Figure 1 is a semilog plot
+fig1 = scf();
+plot2d(y,x,[1,2],logflag="nl")
+legends(['Length of x1','Length of x3'],style_plot,opt="ur",font_size=1);
+change_plot_attribs('Time','Data','Sample semi-log plot',5,5,3)
+
+
+//Figure 2 is a loglog plot
+fig2 = scf();
+plot2d(y,x,style_plot,logflag="ll")
+legends(['Length of x1','Length of x3'],style_plot,opt="ur",font_size=1);
+change_plot_attribs('Time','Data','Figure2 (loglog)',5,5,3)
+
diff --git a/Tutorial02-Plots/Scilab_code/Tutotial2_multi_plotting.sce b/Tutorial02-Plots/Scilab_code/Tutotial2_multi_plotting.sce
new file mode 100644
index 0000000..ec5b193
--- /dev/null
+++ b/Tutorial02-Plots/Scilab_code/Tutotial2_multi_plotting.sce
@@ -0,0 +1,38 @@
+//This script demonstrates multi-plotting in Scilab
+clear
+clc
+exec change_plot_attribs.sci;
+
+//Import data from file
+Data = csvRead('/home/chayan/Documents/scilab-tutorials/Tutorial2_Plot/Data/Tut2_data1.csv');
+
+//Segregate the data into variables
+t = Data(:,1);
+x = [Data(:,2:4)]
+
+//Style of plot
+style_plot = [1,2,4]
+
+//Fixing the range of plot
+//Range is defined by [xmin,ymin,xmax,ymax]
+range_of_plot = [1,-1e-5,15,8e-05];
+
+//Plotting y versus two data sets
+//plot2d(t,x,style_plot);
+plot2d(t,x,style_plot,rect=range_of_plot);
+
+//Font size and labels for legends
+//For legends "ur" for upper right
+legends(['x1','x2', 'x3'],style_plot,opt="ur",font_size=2);
+
+//Call function to change plot attributes
+change_plot_attribs('Time','Data','Data versus Time',5,5,3)
+
+//For thickness of the plots
+attrib = gcf();
+attrib.children(2).children(1).children.thickness = 3;
+
+
+
+
+
diff --git a/Tutorial02-Plots/Scilab_code/Tutotial2_plot_save.sce b/Tutorial02-Plots/Scilab_code/Tutotial2_plot_save.sce
new file mode 100644
index 0000000..a3da8f3
--- /dev/null
+++ b/Tutorial02-Plots/Scilab_code/Tutotial2_plot_save.sce
@@ -0,0 +1,32 @@
+//This script demonstrate exporting plots to svg/pdf files
+clear
+clc
+
+//Import data from file
+Data = csvRead('/home/chayan/Documents/scilab-tutorials/Tutorial2_Plot/Data/Tut2_data1.csv');
+
+//Segregate the data into variables
+t = Data(:,1);
+x = Data(:,2)
+
+//Ploting the figure. Name of the figure is fig1;
+//Use the field Linewidth to specify thickness of the plot
+fig1 = scf(1);
+plot(t,x,'Linewidth',3);
+
+//Adding title, xlabels and ylabels
+//Changing thickness and textsize in plot
+attrib_axes = gca(); //Attributes of axes of active handle
+attrib_axes.x_label.text = 'Time'; //X-label
+attrib_axes.y_label.text = 'Data'; //Y-label
+attrib_axes.title.text = 'x versus t'; //Title of the plot
+attrib_axes.x_label.font_size = 5; //X_label font size
+attrib_axes.y_label.font_size = 5; //Y_label font size
+attrib_axes.title.font_size = 5; //Title font size
+attrib_axes.font_size = 4; //Font size of x-axis and y-axis
+
+//Export Figure 1 as svg file
+xs2svg(fig1,'plot_y_versus_x1');
+
+//Export Figure 2 as pdf file
+xs2pdf(fig1,'plot_y_versus_x1');
diff --git a/Tutorial02-Plots/Scilab_code/Tutotial2_plot_save_func.sce b/Tutorial02-Plots/Scilab_code/Tutotial2_plot_save_func.sce
new file mode 100644
index 0000000..d8f9963
--- /dev/null
+++ b/Tutorial02-Plots/Scilab_code/Tutotial2_plot_save_func.sce
@@ -0,0 +1,27 @@
+//This script demonstrate exporting plots to svg/pdf files
+clear
+clc
+
+exec change_plot_attribs.sci;
+
+//Import data from file
+Data = csvRead('/home/chayan/Documents/scilab-tutorials/Tutorial2_Plot/Data/Tut2_data1.csv');
+
+//Segregate the data into variables
+t = Data(:,1);
+x = Data(:,2)
+
+//Ploting the figure. Name of the figure is fig1;
+//Use the field Linewidth to specify thickness of the plot
+fig1 = scf(1);
+plot(t,x,'Linewidth',3);
+
+//Call function to change plot attributes
+//Arguments (x_label,y_label,title,label_size,title_size,fontsize)
+change_plot_attribs('Time','Data','x versus t',7,6,3)
+
+//Export Figure 1 as svg file
+xs2svg(fig1,'plot_y_versus_x1');
+
+//Export Figure 2 as pdf file
+xs2pdf(fig1,'plot_y_versus_x1');
diff --git a/Tutorial02-Plots/Scilab_code/Tutotial2_plotting.sce b/Tutorial02-Plots/Scilab_code/Tutotial2_plotting.sce
new file mode 100644
index 0000000..5494863
--- /dev/null
+++ b/Tutorial02-Plots/Scilab_code/Tutotial2_plotting.sce
@@ -0,0 +1,16 @@
+//This script demonstrate basic plot command in Scilab
+clear
+clc
+
+//Import data from file
+Data = csvRead('/home/chayan/Documents/scilab-tutorials/Tutorial2_Plot/Data/Tut2_data1.csv');
+
+//Segregate the data into variables
+t = Data(:,1);
+x = Data(:,2);
+
+//Plotting x versus t
+plot(t,x);
+
+xtitle('A x versus t plot','Time','Data')
+
diff --git a/Tutorial02-Plots/Scilab_code/change_plot_attribs.sci b/Tutorial02-Plots/Scilab_code/change_plot_attribs.sci
new file mode 100644
index 0000000..68a04bd
--- /dev/null
+++ b/Tutorial02-Plots/Scilab_code/change_plot_attribs.sci
@@ -0,0 +1,10 @@
+function change_plot_attribs(xlab,ylab,caption,labelsize,capsize,fontsize)
+ attrib_axes = gca(); //Attributes of axes of active handle
+ attrib_axes.x_label.text = xlab; //X-label
+ attrib_axes.y_label.text = ylab; //Y-label
+ attrib_axes.title.text = caption; //Title of the plot
+ attrib_axes.x_label.font_size = labelsize; //X_label font size
+ attrib_axes.y_label.font_size = labelsize; //Y_label font size
+ attrib_axes.title.font_size = capsize; //Title font size
+ attrib_axes.font_size = fontsize; //Font size of x-axis and y-axis
+endfunction