# [Scilab-users] spline and color plot on the chart

8 messages
Open this post in threaded view
|

## [Scilab-users] spline and color plot on the chart

 Good night friends, I wrote an email before, but I believe that I was not clear in my words and so I will write more clearly. In this annex 1, I have the graph I am generating. Basically I am extracting values of x (speed) and y (torque) from excel and generating vectors of x [] and y [] to plot internal lines. I want to smooth these lines, but the functions of the scilab are only for growing points. I thought about creating cubic splines manually, but I don't know how to do it. Can anybody help me ? In addition, I would like to color my chart with level colors according to the colorbar, but I am not able to implement contour2d for this case. thanks. -- Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: spline and color plot on the chart

 Daniel, You may try with lsq_spline, which unlike ordinary spline, doesn't fit the data exactly, and it doesn't need the data with any particular order. But trying to understand your graph, it seems that you should parametrize two variables independently, each one with respect to the index. Something like this: x = [x1, x2, ..., xn] y = [y1, y2, ..., yn] Then you approximate x vs 1:n and y vs 1:n using spline or lsq_splin. Finally you plot xs vs ys (the smoothed versions of x and y)  Regards, Federico Miyara On 07/04/2020 22:48, Daniel Stringari wrote: ```Good night friends, I wrote an email before, but I believe that I was not clear in my words and so I will write more clearly. In this annex 1, I have the graph I am generating. Basically I am extracting values of x (speed) and y (torque) from excel and generating vectors of x [] and y [] to plot internal lines. I want to smooth these lines, but the functions of the scilab are only for growing points. I thought about creating cubic splines manually, but I don't know how to do it. Can anybody help me ? In addition, I would like to color my chart with level colors according to the colorbar, but I am not able to implement contour2d for this case. thanks. -- Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users ``` _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: spline and color plot on the chart

 Federico,I appreciate the help. Below is a list of the code on which I try to plot the data with Isq_splin:c = size (vt12)a = 0b = c (1) // c (1) = 16n = c (1)x = linspace (a, b, n)[y, d] = lsq_splin (vt12, vv12, x ')plot (y, d, 'r')xlabel ('Speed (rpm)')ylabel ('Torque (Nm)')title ('Torque x speed values')//vt12 = 5350.3 5380.19 5410.08 5439.96 4149.5 4179.35 3756.57 3602.73 3568.12 3597.85 3681.91 3711.59 6143.24 6172.86 6202.49 6232.1//vv12 = 40.16   39.93   39.71   39.49   69.04   68.54   95.32   119.26   140.49   139.32   155.62   154.37   93.27   92.82   92.38   91.94but I'm getting the error: lsq_plin: There are not enough points to adjust.Does anyone understand what could be wrong?On Wed, Apr 8, 2020 at 12:54 AM Federico Miyara <[hidden email]> wrote: Daniel, You may try with lsq_spline, which unlike ordinary spline, doesn't fit the data exactly, and it doesn't need the data with any particular order. But trying to understand your graph, it seems that you should parametrize two variables independently, each one with respect to the index. Something like this: x = [x1, x2, ..., xn] y = [y1, y2, ..., yn] Then you approximate x vs 1:n and y vs 1:n using spline or lsq_splin. Finally you plot xs vs ys (the smoothed versions of x and y)  Regards, Federico Miyara On 07/04/2020 22:48, Daniel Stringari wrote: ```Good night friends, I wrote an email before, but I believe that I was not clear in my words and so I will write more clearly. In this annex 1, I have the graph I am generating. Basically I am extracting values of x (speed) and y (torque) from excel and generating vectors of x [] and y [] to plot internal lines. I want to smooth these lines, but the functions of the scilab are only for growing points. I thought about creating cubic splines manually, but I don't know how to do it. Can anybody help me ? In addition, I would like to color my chart with level colors according to the colorbar, but I am not able to implement contour2d for this case. thanks. -- Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users ``` _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: spline and color plot on the chart

 Daniel: I think you meant to include more than 1 point. You seem to have confused the dimensions given by function size. But anyway this doesn't seem to be what I suggested. You should compute a spline for vt12 vs x (the right x, using b = c(2)) and another one for vv12. You don't need in this case to use lsq_splin, but in case you want to use it, the third argument has usually less points than the other two, for instance   [yvt, dvt] = lsq_splin (x, vt12, linspace(a, b, 8)) The output argumnts should be used in interp,as shown in the lsq_splin help. Once you have a smoothed version of vt12_s vs x_s and of vv12_s vs x_s you plot vv12_s vs vt12_s Regards, Federico Miyara On 10/04/2020 21:05, Daniel Stringari wrote: c = size (vt12) a = 0 b = c (1) // c (1) = 16 n = c (1) x = linspace (a, b, n) [y, d] = lsq_splin (vt12, vv12, x ') plot (y, d, 'r') xlabel ('Speed (rpm)') ylabel ('Torque (Nm)') title ('Torque x speed values') //vt12 = 5350.3 5380.19 5410.08 5439.96 4149.5 4179.35 3756.57 3602.73 3568.12 3597.85 3681.91 3711.59 6143.24 6172.86 6202.49 6232.1 //vv12 = 40.16   39.93   39.71   39.49   69.04   68.54   95.32   119.26   140.49   139.32   155.62   154.37   93.27   92.82   92.38   91.94 _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: spline and color plot on the chart

 In reply to this post by Daniel Stringari Reading the lsq_splin function help, should help in this case: The error “There are not enough points to adjust” is due to the fact that the 3rd input to lsq_splin (‘x’ the list of breakpoints of the cubic spline) has values all lying outside the input vt12 variable range (39.49 to 155.62).     From: users <[hidden email]> On Behalf Of Daniel Stringari Sent: Saturday, April 11, 2020 3:06 AM To: Users mailing list for Scilab <[hidden email]> Subject: Re: [Scilab-users] spline and color plot on the chart   Federico, I appreciate the help. Below is a list of the code on which I try to plot the data with Isq_splin: c = size (vt12) a = 0 b = c (1) // c (1) = 16 n = c (1) x = linspace (a, b, n) [y, d] = lsq_splin (vt12, vv12, x ') plot (y, d, 'r') xlabel ('Speed (rpm)') ylabel ('Torque (Nm)') title ('Torque x speed values') //vt12 = 5350.3 5380.19 5410.08 5439.96 4149.5 4179.35 3756.57 3602.73 3568.12 3597.85 3681.91 3711.59 6143.24 6172.86 6202.49 6232.1 //vv12 = 40.16   39.93   39.71   39.49   69.04   68.54   95.32   119.26   140.49   139.32   155.62   154.37   93.27   92.82   92.38   91.94 but I'm getting the error: lsq_plin: There are not enough points to adjust. Does anyone understand what could be wrong?   _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: spline and color plot on the chart

 In reply to this post by Daniel Stringari Daniel, I'm afraid I was a bit confused with your application case. I assumed that there was an independent variable such as time or other which the other two, vt12 and vv12, depend on. If this were the case, the expected graph could be a curve or rather a trajectory with some hysteresis. But if your data are just measurements in no particular order of what is a functional relation of one variable respect to the other, for instance vt12 = f(vv12), then the approach is different. You should basically sort the independent variable in increasing order using gsort and apply the same sorting to the dependent variable: [x, I] = gsort(vv12,"g","i"); y = vt12(I);     Then you can proceed to interpolate with spline or lsg_splin. Regards, Federico Miyara On 10/04/2020 21:05, Daniel Stringari wrote: Federico, I appreciate the help. Below is a list of the code on which I try to plot the data with Isq_splin: c = size (vt12) a = 0 b = c (1) // c (1) = 16 n = c (1) x = linspace (a, b, n) [y, d] = lsq_splin (vt12, vv12, x ') plot (y, d, 'r') xlabel ('Speed (rpm)') ylabel ('Torque (Nm)') title ('Torque x speed values') //vt12 = 5350.3 5380.19 5410.08 5439.96 4149.5 4179.35 3756.57 3602.73 3568.12 3597.85 3681.91 3711.59 6143.24 6172.86 6202.49 6232.1 //vv12 = 40.16   39.93   39.71   39.49   69.04   68.54   95.32   119.26   140.49   139.32   155.62   154.37   93.27   92.82   92.38   91.94 but I'm getting the error: lsq_plin: There are not enough points to adjust. Does anyone understand what could be wrong? On Wed, Apr 8, 2020 at 12:54 AM Federico Miyara <[hidden email]> wrote: Daniel, You may try with lsq_spline, which unlike ordinary spline, doesn't fit the data exactly, and it doesn't need the data with any particular order. But trying to understand your graph, it seems that you should parametrize two variables independently, each one with respect to the index. Something like this: x = [x1, x2, ..., xn] y = [y1, y2, ..., yn] Then you approximate x vs 1:n and y vs 1:n using spline or lsq_splin. Finally you plot xs vs ys (the smoothed versions of x and y)  Regards, Federico Miyara On 07/04/2020 22:48, Daniel Stringari wrote: ```Good night friends, I wrote an email before, but I believe that I was not clear in my words and so I will write more clearly. In this annex 1, I have the graph I am generating. Basically I am extracting values of x (speed) and y (torque) from excel and generating vectors of x [] and y [] to plot internal lines. I want to smooth these lines, but the functions of the scilab are only for growing points. I thought about creating cubic splines manually, but I don't know how to do it. Can anybody help me ? In addition, I would like to color my chart with level colors according to the colorbar, but I am not able to implement contour2d for this case. thanks. -- Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users ``` _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users ```_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users ``` _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: spline and color plot on the chart

 Federico,I am extracting the values of the vectors (vv12 and vt12) from a logic in which it takes data from a spreadsheet that was generated using specific software. The vectors (vv12 and vt12) represent an efficiency curve within the torque x speed plane, I have eleven more of these vectors that vary in size. I believe that I do not have a role in which one depends on the other directly. I tried to follow your first reasoning and arrived at a routine that does not report errors but is not smoothing my curve either, follow the routine:```clc clear vt12 = [5350.3,5380.19,5410.08,5439.96,4149.5,4179.35,3756.57,3602.73,3568.12,3597.85,3681.91,3711.59,6143.24,6172.86,6202.49,6232.1] vv12 = [40.16,39.93,39.71,39.49,69.04,68.54,95.32,119.26,140.49,139.32,155.62,154.37,93.27,92.82,92.38,91.94] c = size (vt12) a = 1 b = c(2) n = c(2) x = linspace (a, b, n) [yvt,dvt] = lsq_splin(x,vt12,linspace (a,b,n)) [yvv,dvv] = lsq_splin(x,vv12,linspace (a,b,n)) ys=interp(linspace (a,b,n),linspace (a,b,n),yvt,dvt) xs=interp(linspace (a,b,n),linspace (a,b,n),yvv,dvv) plot (ys,xs,'r') xlabel ('Speed (rpm)') ylabel ('Torque (Nm)') title ('Torque x speed values')````Any idea how I can proceed with my goal of smoothing the curve to use the color map later?`On Sat, Apr 11, 2020 at 9:18 PM Federico Miyara <[hidden email]> wrote: Daniel, I'm afraid I was a bit confused with your application case. I assumed that there was an independent variable such as time or other which the other two, vt12 and vv12, depend on. If this were the case, the expected graph could be a curve or rather a trajectory with some hysteresis. But if your data are just measurements in no particular order of what is a functional relation of one variable respect to the other, for instance vt12 = f(vv12), then the approach is different. You should basically sort the independent variable in increasing order using gsort and apply the same sorting to the dependent variable: [x, I] = gsort(vv12,"g","i"); y = vt12(I);     Then you can proceed to interpolate with spline or lsg_splin. Regards, Federico Miyara On 10/04/2020 21:05, Daniel Stringari wrote: Federico, I appreciate the help. Below is a list of the code on which I try to plot the data with Isq_splin: c = size (vt12) a = 0 b = c (1) // c (1) = 16 n = c (1) x = linspace (a, b, n) [y, d] = lsq_splin (vt12, vv12, x ') plot (y, d, 'r') xlabel ('Speed (rpm)') ylabel ('Torque (Nm)') title ('Torque x speed values') //vt12 = 5350.3 5380.19 5410.08 5439.96 4149.5 4179.35 3756.57 3602.73 3568.12 3597.85 3681.91 3711.59 6143.24 6172.86 6202.49 6232.1 //vv12 = 40.16   39.93   39.71   39.49   69.04   68.54   95.32   119.26   140.49   139.32   155.62   154.37   93.27   92.82   92.38   91.94 but I'm getting the error: lsq_plin: There are not enough points to adjust. Does anyone understand what could be wrong? On Wed, Apr 8, 2020 at 12:54 AM Federico Miyara <[hidden email]> wrote: Daniel, You may try with lsq_spline, which unlike ordinary spline, doesn't fit the data exactly, and it doesn't need the data with any particular order. But trying to understand your graph, it seems that you should parametrize two variables independently, each one with respect to the index. Something like this: x = [x1, x2, ..., xn] y = [y1, y2, ..., yn] Then you approximate x vs 1:n and y vs 1:n using spline or lsq_splin. Finally you plot xs vs ys (the smoothed versions of x and y)  Regards, Federico Miyara On 07/04/2020 22:48, Daniel Stringari wrote: ```Good night friends, I wrote an email before, but I believe that I was not clear in my words and so I will write more clearly. In this annex 1, I have the graph I am generating. Basically I am extracting values of x (speed) and y (torque) from excel and generating vectors of x [] and y [] to plot internal lines. I want to smooth these lines, but the functions of the scilab are only for growing points. I thought about creating cubic splines manually, but I don't know how to do it. Can anybody help me ? In addition, I would like to color my chart with level colors according to the colorbar, but I am not able to implement contour2d for this case. thanks. -- Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users ``` _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users ```_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users ``` _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: spline and color plot on the chart

 Daniel, Looking at the graph from your script there are two striking things. First, your data seems to be heavily clustered at certain regions, I mean, several points very close to each other, then a gap without data (which is conveniently interpolated by the plot clause), then another cluster and so on. From a statistical point of view, each cluster counts as a single point. You don't have information of what happens between neighboring clusters. The second striking thing is that you don't seem to be using the spline concept correctly. You are using it to approximate the same points you already have. To make things worse, you are using lsq_splin (a cannon to kill a fly), which is normally used to get a simpler spline by using less breakpoints than the total number of available points. This will normally give a smooth approximation of data, so that the spline will not necessarily pass through any of your points. It is used when the data set is inconsistent due to noise or measurement errors to avoid over representing irrelevant features. If you use it with the same number of breakpoints as the available data, I guess you will have a spline that pass through all the points (this will be the least-square solution since the error will be zero), so it is the same as an ordinary spline interpolation. The correct way to use a spline is to use it to interpolate your data, i.e., to have much more points than the original ones, or to have them more evenly distributed. You are representing your very same data using a spline, so there is no smoothing. The plot function does some interpolation job, but linearly: it connects points with straight segments. You need to calculate more points and more evenly distributed with your spline, but probably you'll be disappointed because the behavior in the large gaps between data clusters may be strangewith some odd oscillations.. If you can, try to generate your data more evenly. Regards, Federico Miyara On 11/04/2020 21:45, Daniel Stringari wrote: Federico, I am extracting the values of the vectors (vv12 and vt12) from a logic in which it takes data from a spreadsheet that was generated using specific software. The vectors (vv12 and vt12) represent an efficiency curve within the torque x speed plane, I have eleven more of these vectors that vary in size. I believe that I do not have a role in which one depends on the other directly. I tried to follow your first reasoning and arrived at a routine that does not report errors but is not smoothing my curve either, follow the routine: ```clc clear vt12 = [5350.3,5380.19,5410.08,5439.96,4149.5,4179.35,3756.57,3602.73,3568.12,3597.85,3681.91,3711.59,6143.24,6172.86,6202.49,6232.1] vv12 = [40.16,39.93,39.71,39.49,69.04,68.54,95.32,119.26,140.49,139.32,155.62,154.37,93.27,92.82,92.38,91.94] c = size (vt12) a = 1 b = c(2) n = c(2) x = linspace (a, b, n) [yvt,dvt] = lsq_splin(x,vt12,linspace (a,b,n)) [yvv,dvv] = lsq_splin(x,vv12,linspace (a,b,n)) ys=interp(linspace (a,b,n),linspace (a,b,n),yvt,dvt) xs=interp(linspace (a,b,n),linspace (a,b,n),yvv,dvv) plot (ys,xs,'r') xlabel ('Speed (rpm)') ylabel ('Torque (Nm)') title ('Torque x speed values')``` ```Any idea how I can proceed with my goal of smoothing the curve to use the color map later? ``` ``` ``` ``` ``` On Sat, Apr 11, 2020 at 9:18 PM Federico Miyara <[hidden email]> wrote: Daniel, I'm afraid I was a bit confused with your application case. I assumed that there was an independent variable such as time or other which the other two, vt12 and vv12, depend on. If this were the case, the expected graph could be a curve or rather a trajectory with some hysteresis. But if your data are just measurements in no particular order of what is a functional relation of one variable respect to the other, for instance vt12 = f(vv12), then the approach is different. You should basically sort the independent variable in increasing order using gsort and apply the same sorting to the dependent variable: [x, I] = gsort(vv12,"g","i"); y = vt12(I);     Then you can proceed to interpolate with spline or lsg_splin. Regards, Federico Miyara On 10/04/2020 21:05, Daniel Stringari wrote: Federico, I appreciate the help. Below is a list of the code on which I try to plot the data with Isq_splin: c = size (vt12) a = 0 b = c (1) // c (1) = 16 n = c (1) x = linspace (a, b, n) [y, d] = lsq_splin (vt12, vv12, x ') plot (y, d, 'r') xlabel ('Speed (rpm)') ylabel ('Torque (Nm)') title ('Torque x speed values') //vt12 = 5350.3 5380.19 5410.08 5439.96 4149.5 4179.35 3756.57 3602.73 3568.12 3597.85 3681.91 3711.59 6143.24 6172.86 6202.49 6232.1 //vv12 = 40.16   39.93   39.71   39.49   69.04   68.54   95.32   119.26   140.49   139.32   155.62   154.37   93.27   92.82   92.38   91.94 but I'm getting the error: lsq_plin: There are not enough points to adjust. Does anyone understand what could be wrong? On Wed, Apr 8, 2020 at 12:54 AM Federico Miyara <[hidden email]> wrote: Daniel, You may try with lsq_spline, which unlike ordinary spline, doesn't fit the data exactly, and it doesn't need the data with any particular order. But trying to understand your graph, it seems that you should parametrize two variables independently, each one with respect to the index. Something like this: x = [x1, x2, ..., xn] y = [y1, y2, ..., yn] Then you approximate x vs 1:n and y vs 1:n using spline or lsq_splin. Finally you plot xs vs ys (the smoothed versions of x and y)  Regards, Federico Miyara On 07/04/2020 22:48, Daniel Stringari wrote: ```Good night friends, I wrote an email before, but I believe that I was not clear in my words and so I will write more clearly. In this annex 1, I have the graph I am generating. Basically I am extracting values of x (speed) and y (torque) from excel and generating vectors of x [] and y [] to plot internal lines. I want to smooth these lines, but the functions of the scilab are only for growing points. I thought about creating cubic splines manually, but I don't know how to do it. Can anybody help me ? In addition, I would like to color my chart with level colors according to the colorbar, but I am not able to implement contour2d for this case. thanks. -- Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users ``` _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users ```_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users ``` _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users ```_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users ``` _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users