|
Gnupltxy.gms |
Top Previous Next |
|
Uwe Schneider and I developed a modified version of Rutherford's Gnuplot.gms trying to achieve simpler syntax (containing more default values than Rutherford) and simpler construction of so called (in spreadsheets) XY graphs where the X and Y data are not common across lines in the graph. The package is distributed through http://www.uni-hamburg.de/Wiss/FB/15/Sustainability/schneider/gnuplot/. To graph data in a GAMS program I need to do three basic things to use Gnupltxy.
LINES Lines in graph /A,B/ POINTS Points on line /1*10/ ORDINATES ORDINATES /X-AXIS,Y-AXIS/ ; TABLE GRAPHDATA(LINES,POINTS,ORDINATES) X-AXIS Y-AXIS 0 A.1 1 1 A.2 2 4 A.3 3 9 A.4 5 25 A.5 10 100 B.1 1 2 B.2 3 6 B.3 7 15 B.4 12 36;
$LIBInclude Gnupltxy GRAPHDATA Y-AXIS X-AXIS
where the first argument after gnupltxy gives the array name, the second name of a set element in the third array position which contains the data coordinates for the y axis and the third the name of a set element in the third array position which contains the data coordinates for the x axis. In turn when I run I get two new windows that automatically open in front of the IDE.
$setglobal gp_title "First Graph of data " $setglobal gp_xlabel "Label for X Axis" $setglobal gp_ylabel "Label for Y Axis" $LIBInclude Gnupltxy GRAPHDATA Y-AXIS X-AXIS GRAPHDATA("B",POINTS,"Y-axis") $GRAPHDATA("B",POINTS,"Y-axis")= 100-GRAPHDATA("B",POINTS,"Y-axis"); $setglobal gp_title "Second Graph of data with modified line B " $LIBInclude Gnupltxy GRAPHDATA Y-AXIS X-AXIS
where the setglobal commands enter labels for axes and graph title This yields both the graph above and the graph below generated in 2 windows with 4 total windows generated.
LOOP (RAPS,RAP=RISKAVER(RAPS); SOLVE EVPORTFOL USING NLP MAXIMIZING OBJ ; VAR = SUM(STOCK, SUM(STOCKS, INVEST.L(STOCK)*COVAR(STOCK,STOCKS)*INVEST.L(STOCKS))) ; OUTPUT("RAP",RAPS)=RAP; OUTPUT(STOCKS,RAPS)=INVEST.L(STOCKS); OUTPUT("OBJ",RAPS)=OBJ.L; OUTPUT("MEAN",RAPS)=SUM(STOCKS, MEAN(STOCKS) * INVEST.L(STOCKS)); OUTPUT("VAR",RAPS) = VAR; OUTPUT("STD",RAPS)=SQRT(VAR); OUTPUT("SHADPRICE",RAPS)=INVESTAV.M; OUTPUT("IDLE",RAPS)=FUNDS-INVESTAV.L ); parameter graphit (*,raps,*); graphit("Frontier",raps,"Mean")=OUTPUT("MEAN",RAPS); graphit("frontier",raps,"Var")=OUTPUT("std",RAPS)**2; *$include gnu_opt.gms * titles $setglobal gp_title "E-V Frontier " $setglobal gp_xlabel "Variance of Income" $setglobal gp_ylabel "Mean Income" $libinclude gnupltxy graphit mean var
Here a model is repeatedly solved and a three dimensional array called graphit is built which contains the name of the line to be graphed (frontier) and the mean and variances. These means and variances were calculated using report writing statements into the array called output as discussed in the chapters on Improving Output via Report Writing and Doing a Comparative Analysis with GAMS. The resultant graph is
|