问题
I'm trying to draw ROC curves using an existing set of values using the following command
plot(X1,Y1,'--rs',X2,Y2,'-*g');
Where X1
,Y1
,X2
and Y2
are matrices that have the same size
However, the lines produced by this command are straight ones.
How can I make them curved lines.
Thanks Aziz
回答1:
MATLAB by default uses straight line approximation to draw your graph in between control points. If you want, you can interpolate in between the points to produce a more realistic graph. Try using interp1 with the 'spline'
option and see how that goes. As such, figure out the minimum and maximum values of both X1
and X2
, then define a grid of points in between the minimum and maximum that have finer granularity. Once you do this, throw this into interp1
and plot your curve. Something like:
%// Find dynamic range of domain for both Xs
minX1 = min(X1);
maxX1 = max(X1);
minX2 = min(X2);
maxX2 = max(X2);
%// Generate grid of points for both Xs
x1Vals = linspace(minX1, maxX1, 100);
x2Vals = linspace(minX2, maxX2, 100);
%// Interpolate the curves
y1Vals = interp1(X1, Y1, x1Vals, 'spline');
y2Vals = interp1(X2, Y2, x2Vals, 'spline');
%// Plot the results
plot(x1Vals,y1Vals,'--rs',x2Vals,y2Vals,'-*g');
linspace generates a grid of points from one end to another, and I specified 100 of these points. I then use interp1
in the way we talked about where you specify control points (X1,Y1,X2,Y2
), then specify the values I want to interpolate with. I use the output values after interpolation and draw the curve.
来源:https://stackoverflow.com/questions/27051100/how-to-plot-a-curved-line-in-matlab-using-a-set-of-points