# Plot coordinate pairs

Plot coordinate pairs
You are encouraged to solve this task according to the task description, using any language you may know.

Plot a function represented as   x',   y'   numerical arrays.

Post the resulting image for the following input arrays (taken from Python's Example section on Time a function):

x = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
y = {2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0};


This task is intended as a subtask for Measure relative performance of sorting algorithms implementations.

Like C, this is often outsourced to another program like gnuplot, but is also possible with GtkAda.

 with Gtk.Main;with Gtk.Window;  use Gtk.Window;with Gtk.Widget;  use Gtk.Widget;with Gtk.Handlers;  use Gtk.Handlers;with Glib;  use Glib;with Gtk.Extra.Plot;  use Gtk.Extra.Plot;with Gtk.Extra.Plot_Data;  use Gtk.Extra.Plot_Data;with Gtk.Extra.Plot_Canvas;  use Gtk.Extra.Plot_Canvas;with Gtk.Extra.Plot_Canvas.Plot;  use Gtk.Extra.Plot_Canvas.Plot; procedure PlotCoords is   package Handler is new Callback (Gtk_Widget_Record);    Window : Gtk_Window;   Plot : Gtk_Plot;   PCP : Gtk_Plot_Canvas_Plot;   Canvas : Gtk_Plot_Canvas;   PlotData : Gtk_Plot_Data;   x, y, dx, dy : Gdouble_Array_Access;    procedure ExitMain (Object : access Gtk_Widget_Record'Class) is   begin      Destroy (Object);  Gtk.Main.Main_Quit;   end ExitMain; begin   x := new Gdouble_Array'(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);   y := new Gdouble_Array'(2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0);   Gtk.Main.Init;   Gtk_New (Window);   Set_Title (Window, "Plot coordinate pairs with GtkAda");   Gtk_New (PlotData);   Set_Points (PlotData, x, y, dx, dy);   Gtk_New (Plot);   Add_Data (Plot, PlotData);   Autoscale (Plot);  Show (PlotData);   Hide_Legends (Plot);   Gtk_New (PCP, Plot);  Show (Plot);   Gtk_New (Canvas, 500, 500);  Show (Canvas);   Put_Child (Canvas, PCP, 0.15, 0.15, 0.85, 0.85);   Add (Window, Canvas);   Show_All (Window);   Handler.Connect (Window, "destroy",      Handler.To_Marshaller (ExitMain'Access));   Gtk.Main.Main;end PlotCoords;

## ALGOL 68

Works with: ALGOL 68 version Revision 1 - extensions to standard used - PRAGMA READ and Currying
Works with: ALGOL 68G version Any - tested with release algol68g-2.4.1.
Example Algol68 plot
File: Plot_coordinate_pairs.a68
#!/usr/bin/algol68g-full --script ## -*- coding: utf-8 -*- # PR READ "prelude/errata.a68" PR;PR READ "prelude/exception.a68" PR;PR READ "prelude/math_lib.a68" PR; CO REQUIRED BY "prelude/graph_2d.a68" CO  MODE GREAL= REAL; # single precision #  FORMAT greal repr = $g(-3,0)$;PR READ "prelude/graph_2d.a68" PR; []REAL x = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9);[]REAL y = (2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0); test:(  REF GRAPHDD test graph = INIT LOC GRAPHDD;  type OF window OF test graph := "gif"; # or gif, ps, X, pnm etc #   title OF test graph := "Plot coordinate pairs";  sub title OF test graph := "Algol68";   interval OF (axis OF test graph)[x axis] := (0, 8);  label OF    (axis OF test graph)[x axis] := "X axis";   interval OF (axis OF test graph)[y axis] := (0, 200);  label OF    (axis OF test graph)[y axis] := "Y axis";   PROC curve = (POINTYIELD yield)VOID:    FOR i TO UPB x DO yield((x[i],y[i])) OD;   (begin curve OF (METHODOF test graph))(~);  (add curve OF   (METHODOF test graph))(curve, (red,solid));  (end curve OF   (METHODOF test graph))(~)); PR READ "postlude/exception.a68" PR

## AutoHotkey

Image - Link, since uploads seem to be disabled currently.

Works with: AutoHotkey_L
(AutoHotkey1.1+)
Library: GDIP
#SingleInstance, Force#NoEnvSetBatchLines, -1OnExit, ExitFileOut := A_Desktop "\MyNewFile.png"Font := "Arial"x := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]y := [2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0]; Uncomment if Gdip.ahk is not in your standard library; #Include, Gdip.ahkif (!pToken := Gdip_Startup()) {	MsgBox, 48, Gdiplus error!, Gdiplus failed to start. Please ensure you have Gdiplus on your system.	ExitApp}If (!Gdip_FontFamilyCreate(Font)) {   MsgBox, 48, Font error!, The font you have specified does not exist on your system.   ExitApp} pBitmap := Gdip_CreateBitmap(900, 900), G := Gdip_GraphicsFromImage(pBitmap), Gdip_SetSmoothingMode(G, 4), pBrush := Gdip_BrushCreateSolid(0xff000000), Gdip_FillRectangle(G, pBrush, -3, -3, 906, 906), Gdip_DeleteBrush(pBrush), pPen1 := Gdip_CreatePen(0xffffcc00, 2), pPen2 := Gdip_CreatePen(0xffffffff, 2), pPen3 := Gdip_CreatePen(0xff447821, 1), pPen4 := Gdip_CreatePen(0xff0066ff, 2), Gdip_DrawLine(G, pPen2, 50, 50, 50, 850), Gdip_DrawLine(G, pPen2, 50, 850, 850, 850), FontOptions1 := "x0 y870 Right cbbffffff r4 s16 Bold", Gdip_TextToGraphics(G, 0, FontOptions1, Font, 40, 20) Loop, % x.MaxIndex() - 1 {	Offset1 := 50 + (x[A_Index] * 80)	, Offset2 := Offset1 + 80	, Gdip_DrawLine(G, pPen1, Offset1, 850 - (y[A_Index] * 4), Offset1 + 80, 850 - (y[A_Index + 1] * 4))} Loop, % x.MaxIndex() {	Offset1 := 50 + ((A_Index - 1) * 80)	, Offset2 := Offset1 + 80	, Offset3 := 45 + (x[A_Index] * 80)	, Offset4 := 845 - (y[A_Index] * 4)	, Gdip_DrawLine(G, pPen2, 45, Offset1, 55, Offset1)	, Gdip_DrawLine(G, pPen2, Offset2, 845, Offset2, 855)	, Gdip_DrawLine(G, pPen3, 50, Offset1, 850, Offset1)	, Gdip_DrawLine(G, pPen3, Offset2, 50, Offset2, 850)	, Gdip_DrawLine(G, pPen4, Offset3, Offset4, Offset3 + 10, Offset4 + 10)	, Gdip_DrawLine(G, pPen4, Offset3, Offset4 + 10, Offset3 + 10, Offset4)	, FontOptions1 := "x0 y" (Offset1 - 7) " Right cbbffffff r4 s16 Bold"	, FontOptions2 := "x" (Offset2 - 7) " y870 Left cbbffffff r4 s16 Bold"	, Gdip_TextToGraphics(G, 220 - (A_Index * 20), FontOptions1, Font, 40, 20)	, Gdip_TextToGraphics(G, A_Index, FontOptions2, Font, 40, 20)} Gdip_DeletePen(pPen1), Gdip_DeletePen(pPen2), Gdip_DeletePen(pPen3), Gdip_DeletePen(pPen4), Gdip_SaveBitmapToFile(pBitmap, FileOut), Gdip_DisposeImage(pBitmap), Gdip_DeleteGraphics(G)Run, % FileOut Exit:Gdip_Shutdown(pToken)ExitApp

## BBC BASIC

      DIM x(9), y(9)      x() = 0,   1,    2,    3,    4,    5,     6,     7,     8,     9      y() = 2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0       ORIGIN 100,100      VDU 23,23,2;0;0;0;      VDU 5       FOR x = 1 TO 9        GCOL 7 : LINE 100*x,720,100*x,0        GCOL 0 : PLOT 0,-10,-4 : PRINT ; x ;      NEXT       FOR y = 20 TO 180 STEP 20        GCOL 7 : LINE 900,4*y,0,4*y        GCOL 0 : PLOT 0,-212,20 : PRINT y ;      NEXT       LINE 0,0,0,720      LINE 0,0,900,0       GCOL 4      FOR i% = 0 TO 9        IF i%=0 THEN          MOVE 100*x(i%),4*y(i%)        ELSE          DRAW 100*x(i%),4*y(i%)        ENDIF      NEXT

## C

We could use the suite provided by Raster graphics operations, but those functions lack a facility to draw text.

Library: libplot
#include <stdio.h>#include <stdlib.h>#include <math.h>#include <plot.h> #define NP 10double x[NP] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};double y[NP] = {2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0}; void minmax(double *x, double *y,	    double *minx, double *maxx, 	    double *miny, double *maxy, int n){  int i;   *minx = *maxx = x[0];  *miny = *maxy = y[0];  for(i=1; i < n; i++) {    if ( x[i] < *minx ) *minx = x[i];    if ( x[i] > *maxx ) *maxx = x[i];    if ( y[i] < *miny ) *miny = y[i];    if ( y[i] > *maxy ) *maxy = y[i];  }} /* likely we must play with this parameter to make the plot looks better   when using different set of data */#define YLAB_HEIGHT_F 0.1#define XLAB_WIDTH_F 0.2  #define XDIV (NP*1.0)#define YDIV (NP*1.0)#define EXTRA_W 0.01#define EXTRA_H 0.01#define DOTSCALE (1.0/150.0) #define MAXLABLEN 32 #define PUSHSCALE(X,Y) pl_fscale((X),(Y))#define POPSCALE(X,Y)  pl_fscale(1.0/(X), 1.0/(Y))#define FMOVESCALE(X,Y) pl_fmove((X)/sx, (Y)/sy) int main(){  int plotter, i;  double minx, miny, maxx, maxy;  double lx, ly;  double xticstep, yticstep, nx, ny;  double sx, sy;   char labs[MAXLABLEN+1];   plotter = pl_newpl("png", NULL, stdout, NULL);  if ( plotter < 0 ) exit(1);  pl_selectpl(plotter);  if ( pl_openpl() < 0 ) exit(1);   /* determines minx, miny, maxx, maxy */  minmax(x, y, &minx, &maxx, &miny, &maxy, NP);   lx = maxx - minx;  ly = maxy - miny;  pl_fspace(floor(minx) - XLAB_WIDTH_F * lx, floor(miny) - YLAB_HEIGHT_F * ly,	    ceil(maxx) + EXTRA_W * lx, ceil(maxy) + EXTRA_H * ly);   /* compute x,y-ticstep */  xticstep = (ceil(maxx) - floor(minx)) / XDIV;  yticstep = (ceil(maxy) - floor(miny)) / YDIV;   pl_flinewidth(0.25);   /* compute scale factors to adjust aspect */  if ( lx < ly ) {    sx = lx/ly;    sy = 1.0;  } else {    sx = 1.0;    sy = ly/lx;  }   pl_erase();   /* a frame... */  pl_fbox(floor(minx), floor(miny),	  ceil(maxx), ceil(maxy));   /* labels and "tics" */  pl_fontname("HersheySerif");  for(ny=floor(miny); ny < ceil(maxy); ny += yticstep) {    pl_fline(floor(minx), ny, ceil(maxx), ny);    snprintf(labs, MAXLABLEN, "%6.2lf", ny);    FMOVESCALE(floor(minx) - XLAB_WIDTH_F * lx, ny);    PUSHSCALE(sx,sy);    pl_label(labs);    POPSCALE(sx,sy);  }  for(nx=floor(minx); nx < ceil(maxx); nx += xticstep) {    pl_fline(nx, floor(miny), nx, ceil(maxy));    snprintf(labs, MAXLABLEN, "%6.2lf", nx);    FMOVESCALE(nx, floor(miny));    PUSHSCALE(sx,sy);    pl_ftextangle(-90);    pl_alabel('l', 'b', labs);    POPSCALE(sx,sy);  }   /* plot data "point" */  pl_fillcolorname("red");  pl_filltype(1);  for(i=0; i < NP; i++)  {    pl_fbox(x[i] - lx * DOTSCALE, y[i] - ly * DOTSCALE,            x[i] + lx * DOTSCALE, y[i] + ly * DOTSCALE);  }   pl_flushpl();  pl_closepl();}

No one would use the previous code to produce a plot (that looks this way; instead, normally we produce data through a program, then we plot the data using e.g. gnuplot or other powerful tools; the result (with gnuplot and without enhancement) could look like this instead.

### Writing EPS

Following code creates a plot in EPS format, with auto scaling and line/symbol/color controls. Plotting function loosely follows Matlab command style. Not thorough by any means, just to give an idea on how this kind of things can be coded.
#include <stdio.h>#include <math.h>#include <string.h> #define N 40double x[N], y[N]; void minmax(double x[], int len, double *base, double *step, int *nstep){	int i;	double diff, minv, maxv;	*step = 1; 	minv = maxv = x[0];	for (i = 1; i < len; i++) {		if (minv > x[i]) minv = x[i];		if (maxv < x[i]) maxv = x[i];	}	if (minv == maxv) {		minv = floor(minv);		maxv =  ceil(maxv);		if (minv == maxv) {			minv--;			maxv++;		}	} else {		diff = maxv - minv;		while (*step < diff) *step *= 10;		while (*step > diff)	   *step /= 10;		if (*step > diff / 2)	   *step /= 5;		else if (*step > diff / 5) *step /= 2;	} 	*base = floor(minv / *step) * *step;	*nstep =  ceil(maxv / *step) - floor(minv / *step);} /* writes an eps with 400 x 300 dimention, using 12 pt font */#define CHARH 12#define CHARW 6#define DIMX 398#define DIMY (300 - CHARH)#define BOTY 20.int plot(double x[], double y[], int len, char *spec){	int nx, ny, i;	double sx, sy, x0, y0;	char buf[100];	int dx, dy, lx, ly;	double ofs_x, ofs_y, grid_x; 	minmax(x, len, &x0, &sx, &nx);	minmax(y, len, &y0, &sy, &ny); 	dx = -log10(sx);	dy = -log10(sy); 	ly = 0;	for (i = 0; i <= ny; i++) {		sprintf(buf, "%g\n", y0 + i * sy);		if (strlen(buf) > ly) ly = strlen(buf);	}	ofs_x = ly * CHARW; 	printf("%%!PS-Adobe-3.0\n%%%%BoundingBox: 0 0 400 300\n"		"/TimesRoman findfont %d scalefont setfont\n"		"/rl{rlineto}def /l{lineto}def /s{setrgbcolor}def "		"/rm{rmoveto}def /m{moveto}def /st{stroke}def\n",		CHARH);	for (i = 0; i <= ny; i++) {		ofs_y = BOTY + (DIMY - BOTY) / ny * i;		printf("0 %g m (%*.*f) show\n",			ofs_y - 4, ly, dy, y0 + i * sy);		if (i) printf("%g %g m 7 0 rl st\n",			ofs_x, ofs_y);	}	printf("%g %g m %g %g l st\n", ofs_x, BOTY, ofs_x, ofs_y); 	for (i = 0; i <= nx; i++) {		sprintf(buf, "%g", x0 + i * sx);		lx = strlen(buf);		grid_x = ofs_x + (DIMX - ofs_x) / nx * i; 		printf("%g %g m (%s) show\n", grid_x - CHARW * lx / 2,			BOTY - 12, buf);		if (i) printf("%g %g m 0 7 rl st\n", grid_x, BOTY);	}	printf("%g %g m %g %g l st\n", ofs_x, BOTY, grid_x, BOTY); 	if (strchr(spec, 'r'))		printf("1 0 0 s\n");	else if (strchr(spec, 'b'))	printf("0 0 1 s\n");	else if (strchr(spec, 'g'))	printf("0 1 0 s\n");	else if (strchr(spec, 'm'))	printf("1 0 1 s\n"); 	if (strchr(spec, 'o'))		printf("/o { m 0 3 rm 3 -3 rl -3 -3 rl -3 3 rl closepath st} def "			".5 setlinewidth\n"); 	if (strchr(spec, '-')) {		for (i = 0; i < len; i++) {			printf("%g %g %s ",				(x[i] - x0) / (sx * nx) * (DIMX - ofs_x) + ofs_x,				(y[i] - y0) / (sy * ny) * (DIMY - BOTY) + BOTY,				i ? "l" : "m");		}		printf("st\n");	} 	if (strchr(spec, 'o'))		for (i = 0; i < len; i++) {			printf("%g %g o ",				(x[i] - x0) / (sx * nx) * (DIMX - ofs_x) + ofs_x,				(y[i] - y0) / (sy * ny) * (DIMY - BOTY) + BOTY);		} 	printf("showpage\n%%EOF"); 	return 0;} int main(){	int i;	for (i = 0; i < N; i++) {		x[i] = (double)i / N * 3.14159 * 6;		y[i] = -1337 + (exp(x[i] / 10) + cos(x[i])) / 100;	}	/* string parts: any of "rgbm": color; "-": draw line; "o": draw symbol */	plot(x, y, N, "r-o");	return 0;}

## C++

 #include <windows.h>#include <string>#include <vector> //--------------------------------------------------------------------------------------------------using namespace std; //--------------------------------------------------------------------------------------------------const int HSTEP = 46, MWID = 40, MHEI = 471;const float VSTEP = 2.3f; //--------------------------------------------------------------------------------------------------class vector2{public:    vector2() { x = y = 0; }    vector2( float a, float b )  { x = a; y = b; }    void set( float a, float b ) { x = a; y = b; }    float x, y;};//--------------------------------------------------------------------------------------------------class myBitmap{public:    myBitmap() : pen( NULL ), brush( NULL ), clr( 0 ), wid( 1 ) {}    ~myBitmap()    {	DeleteObject( pen );	DeleteObject( brush );	DeleteDC( hdc );	DeleteObject( bmp );    }     bool create( int w, int h )    {	BITMAPINFO    bi;	ZeroMemory( &bi, sizeof( bi ) );	bi.bmiHeader.biSize        = sizeof( bi.bmiHeader );	bi.bmiHeader.biBitCount    = sizeof( DWORD ) * 8;	bi.bmiHeader.biCompression = BI_RGB;	bi.bmiHeader.biPlanes      = 1;	bi.bmiHeader.biWidth       =  w;	bi.bmiHeader.biHeight      = -h; 	HDC dc = GetDC( GetConsoleWindow() );	bmp = CreateDIBSection( dc, &bi, DIB_RGB_COLORS, &pBits, NULL, 0 );	if( !bmp ) return false; 	hdc = CreateCompatibleDC( dc );	SelectObject( hdc, bmp );	ReleaseDC( GetConsoleWindow(), dc ); 	width = w; height = h;	return true;    }     void clear( BYTE clr = 0 )    {	memset( pBits, clr, width * height * sizeof( DWORD ) );    }     void setBrushColor( DWORD bClr )    {	if( brush ) DeleteObject( brush );	brush = CreateSolidBrush( bClr );	SelectObject( hdc, brush );    }     void setPenColor( DWORD c ) { clr = c; createPen(); }     void setPenWidth( int w )   { wid = w; createPen(); }     void saveBitmap( string path )    {	BITMAPFILEHEADER fileheader;	BITMAPINFO       infoheader;	BITMAP           bitmap;	DWORD            wb; 	GetObject( bmp, sizeof( bitmap ), &bitmap );	DWORD* dwpBits = new DWORD[bitmap.bmWidth * bitmap.bmHeight]; 	ZeroMemory( dwpBits, bitmap.bmWidth * bitmap.bmHeight * sizeof( DWORD ) );	ZeroMemory( &infoheader, sizeof( BITMAPINFO ) );	ZeroMemory( &fileheader, sizeof( BITMAPFILEHEADER ) ); 	infoheader.bmiHeader.biBitCount = sizeof( DWORD ) * 8;	infoheader.bmiHeader.biCompression = BI_RGB;	infoheader.bmiHeader.biPlanes = 1;	infoheader.bmiHeader.biSize = sizeof( infoheader.bmiHeader );	infoheader.bmiHeader.biHeight = bitmap.bmHeight;	infoheader.bmiHeader.biWidth = bitmap.bmWidth;	infoheader.bmiHeader.biSizeImage = bitmap.bmWidth * bitmap.bmHeight * sizeof( DWORD ); 	fileheader.bfType    = 0x4D42;	fileheader.bfOffBits = sizeof( infoheader.bmiHeader ) + sizeof( BITMAPFILEHEADER );	fileheader.bfSize    = fileheader.bfOffBits + infoheader.bmiHeader.biSizeImage; 	GetDIBits( hdc, bmp, 0, height, ( LPVOID )dwpBits, &infoheader, DIB_RGB_COLORS ); 	HANDLE file = CreateFile( path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );	WriteFile( file, &fileheader, sizeof( BITMAPFILEHEADER ), &wb, NULL );	WriteFile( file, &infoheader.bmiHeader, sizeof( infoheader.bmiHeader ), &wb, NULL );	WriteFile( file, dwpBits, bitmap.bmWidth * bitmap.bmHeight * 4, &wb, NULL );	CloseHandle( file ); 	delete [] dwpBits;    }     HDC getDC() const     { return hdc; }    int getWidth() const  { return width; }    int getHeight() const { return height; } private:    void createPen()    {	if( pen ) DeleteObject( pen );	pen = CreatePen( PS_SOLID, wid, clr );	SelectObject( hdc, pen );    }     HBITMAP bmp;    HDC     hdc;    HPEN    pen;    HBRUSH  brush;    void    *pBits;    int     width, height, wid;    DWORD   clr;};//--------------------------------------------------------------------------------------------------class plot{public:    plot() { bmp.create( 512, 512 ); }     void draw( vector<vector2>* pairs )    {	bmp.clear( 0xff );	drawGraph( pairs );	plotIt( pairs ); 	HDC dc = GetDC( GetConsoleWindow() );	BitBlt( dc, 0, 30, 512, 512, bmp.getDC(), 0, 0, SRCCOPY );	ReleaseDC( GetConsoleWindow(), dc );	//bmp.saveBitmap( "f:\\rc\\plot.bmp" );    } private:    void drawGraph( vector<vector2>* pairs )    {	HDC dc = bmp.getDC();	bmp.setPenColor( RGB( 240, 240, 240 ) );	DWORD b = 11, c = 40, x; 	RECT rc; char txt[8]; 	for( x = 0; x < pairs->size(); x++ )	{	    MoveToEx( dc, 40, b, NULL ); LineTo( dc, 500, b );	    MoveToEx( dc, c, 11, NULL ); LineTo( dc, c, 471 ); 	    wsprintf( txt, "%d", ( pairs->size() - x ) * 20 );	    SetRect( &rc, 0, b - 9, 36, b + 11 );	    DrawText( dc, txt, lstrlen( txt ), &rc, DT_RIGHT | DT_VCENTER | DT_SINGLELINE ); 	    wsprintf( txt, "%d", x );	    SetRect( &rc, c - 8, 472, c + 8, 492 );	    DrawText( dc, txt, lstrlen( txt ), &rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE ); 	    c += 46; b += 46;	} 	SetRect( &rc, 0, b - 9, 36, b + 11 );	DrawText( dc, "0", 1, &rc, DT_RIGHT | DT_VCENTER | DT_SINGLELINE ); 	bmp.setPenColor( 0 ); bmp.setPenWidth( 3 );	MoveToEx( dc, 40, 11, NULL ); LineTo( dc, 40, 471 );	MoveToEx( dc, 40, 471, NULL ); LineTo( dc, 500, 471 );    }     void plotIt( vector<vector2>* pairs )    {		HDC dc = bmp.getDC();	HBRUSH br = CreateSolidBrush( 255 );	RECT rc; 	bmp.setPenColor( 255 ); bmp.setPenWidth( 2 );	vector<vector2>::iterator it = pairs->begin();	int a = MWID + HSTEP * static_cast<int>( ( *it ).x ), b = MHEI - static_cast<int>( VSTEP * ( *it ).y );	MoveToEx( dc, a, b, NULL );	SetRect( &rc, a - 3, b - 3, a + 3, b + 3 ); FillRect( dc, &rc, br ); 	it++;	for( ; it < pairs->end(); it++ )	{	    a = MWID + HSTEP * static_cast<int>( ( *it ).x );	    b = MHEI - static_cast<int>( VSTEP * ( *it ).y );	    SetRect( &rc, a - 3, b - 3, a + 3, b + 3 );	    FillRect( dc, &rc, br ); LineTo( dc, a, b );	} 	DeleteObject( br );    }     myBitmap bmp;};//--------------------------------------------------------------------------------------------------int main( int argc, char* argv[] ){    ShowWindow( GetConsoleWindow(), SW_MAXIMIZE );    plot pt;    vector<vector2> pairs;    pairs.push_back( vector2( 0, 2.7f ) ); pairs.push_back( vector2( 1, 2.8f ) );    pairs.push_back( vector2( 2.0f, 31.4f ) ); pairs.push_back( vector2( 3.0f, 38.1f ) );    pairs.push_back( vector2( 4.0f, 58.0f ) ); pairs.push_back( vector2( 5.0f, 76.2f ) );    pairs.push_back( vector2( 6.0f, 100.5f ) ); pairs.push_back( vector2( 7.0f, 130.0f ) );    pairs.push_back( vector2( 8.0f, 149.3f ) ); pairs.push_back( vector2( 9.0f, 180.0f ) );     pt.draw( &pairs );    system( "pause" );     return 0;}//--------------------------------------------------------------------------------------------------

## Clojure

Library: incanter
(use '(incanter core stats charts))(def x (range 0 10))(def y '(2.7 2.8 31.4 38.1 58.0 76.2 100.5 130.0 149.3 180.0))(view (xy-plot x y))
Output:

## EchoLisp

Resulting image here.

 (lib 'plot) (define ys #(2.7 2.8 31.4 38.1 58.0 76.2 100.5 130.0 149.3 180.0) )(define (f n) [ys n]) (plot-sequence f 9)    → (("x:auto" 0 9) ("y:auto" 2 198))(plot-grid 1 20)(plot-text " Rosetta plot coordinate pairs" 0 10 "white")

## Erlang

Using Eplot to produce PNG.

 -module( plot_coordinate_pairs ). -export( [task/0, to_png_file/3] ). task() ->	Xs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],	Ys = [2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0],	File = "plot_coordinate_pairs",	to_png_file( File, Xs, Ys ). to_png_file( File, Xs, Ys ) ->	PNG = egd_chart:graph( [{File, lists:zip(Xs, Ys)}] ),	file:write_file( File ++ ".png", PNG ).

The result looks like this.

## F#

Using the F# for Visualization library:

alt text
#r @"C:\Program Files\FlyingFrog\FSharpForVisualization.dll" let x = Seq.map float [|0; 1; 2; 3; 4; 5; 6; 7; 8; 9|]let y = [|2.7; 2.8; 31.4; 38.1; 58.0; 76.2; 100.5; 130.0; 149.3; 180.0|] open FlyingFrog.Graphics Plot([Data(Seq.zip x y)], (0.0, 9.0))

## gnuplot

Example gnuplot output
unset key  # Only one data set, so the key is uninformative plot '-'   # '-' can be replaced with a filename, to read data from that file.  0   2.7  1   2.8  2  31.4  3  38.1  4  68.0  5  76.2  6 100.5  7 130.0  8 149.3  9 180.0e

## Go

### gnuplot

Output is the same as for the gnuplot example on this page.

A program can of course supply commands and data to gnuplot as prepared files. For the spirit of controlling plotting with the native language however, this example shows how commands and data can be prepared programatically and supplied to gnuplot through stdin.

package main import (  "fmt"  "log"  "os/exec") var (  x = []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}  y = []float64{2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0}) func main() {  g := exec.Command("gnuplot", "-persist")  w, err := g.StdinPipe()  if err != nil {    log.Fatal(err)  }  if err = g.Start(); err != nil {    log.Fatal(err)  }  fmt.Fprintln(w, "unset key; plot '-'")  for i, xi := range x {    fmt.Fprintf(w, "%d %f\n", xi, y[i])  }  fmt.Fprintln(w, "e")  w.Close()  g.Wait()}

### gonum/plot

Library: gonum/plot
package main import (    "log"     "github.com/gonum/plot"    "github.com/gonum/plot/plotter"    "github.com/gonum/plot/plotutil"    "github.com/gonum/plot/vg") var (    x = []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}    y = []float64{2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0}) func main() {    pts := make(plotter.XYs, len(x))    for i, xi := range x {        pts[i] = struct{ X, Y float64 }{float64(xi), y[i]}    }    p, err := plot.New()    if err != nil {        log.Fatal(err)    }    if err = plotutil.AddScatters(p, pts); err != nil {        log.Fatal(err)    }    if err := p.Save(3*vg.Inch, 3*vg.Inch, "points.svg"); err != nil {        log.Fatal(err)    }}

## Groovy

Using JFreeChart and Groovy Swing Builder

Screenshot of groovy solution
import groovy.swing.SwingBuilderimport javax.swing.JFrameimport org.jfree.chart.ChartFactoryimport org.jfree.chart.ChartPanelimport org.jfree.data.xy.XYSeriesimport org.jfree.data.xy.XYSeriesCollectionimport org.jfree.chart.plot.PlotOrientation def chart = {    x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]    y = [2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0]     def series = new XYSeries('plots')    [x, y].transpose().each { x, y -> series.add x, y }     def labels = ["Plot Demo", "X", "Y"]    def data = new XYSeriesCollection(series)    def options = [false, true, false]     def chart = ChartFactory.createXYLineChart(*labels, data, PlotOrientation.VERTICAL, *options)    new ChartPanel(chart)} new SwingBuilder().edt {    frame(title:'Plot coordinate pairs', defaultCloseOperation:JFrame.EXIT_ON_CLOSE, pack:true, show:true) {        widget(chart())    }}

gnuplot is a package from HackageDB.

import Graphics.Gnuplot.Simple pnts = [2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0] doPlot = plotPathStyle [ ( Title "plotting dots" )]            (PlotStyle Points (CustomStyle []))  (zip [0..] pnts)

## HicEst

REAL :: n=10, x(n), y(n) x = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)y = (2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0) WINDOW(WINdowhandle=wh, Width=-300, Height=-300, X=1, TItle='Rosetta')AXIS(WINdowhandle=wh, Title='x values', Yaxis, Title='y values')LINE(X=x, Y=y, SymbolDiameter=2)

Sample Output
Library: Imager

## Python

### Library: matplotlib

matplotlib plot of x,y arrays

Interactive session:

>>> x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>>> y = [2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0] >>> import pylab>>> pylab.plot(x, y, 'bo')>>> pylab.savefig('qsort-range-10-9.png')

See some other examples:

### Library: VPython

 from visual import *from visual.graph import * plot1 = gdisplay( title='VPython Plot-Demo',                   xtitle='x',                  ytitle='y    (click and drag mouse to see coordinates)',                  foreground=color.black,                  background=color.white,                   x=0, y=0,                  width=400, height=400,                  xmin=0, xmax=10,                   ymin=0, ymax=200 ) f1 = gdots(color=color.red)                 # create plot-object f1.plot(pos= (0,   2.7), color=color.blue ) # add a single pointf1.plot(pos=[(1,   2.8),                    # add a list of points             (2,  31.4),             (3,  38.1),              (4,  58.0),             (5,  76.2),             (6, 100.5),             (7, 130.0),             (8, 149.3),             (9, 180.0) ]        )label(display=plot1.display, text="Look here",      pos=(6,100.5), xoffset=30,yoffset=-20 )

## R

R has several different plotting paradigms. First we define the data.

x <- c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)y <- c(2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0)

### Base graphics

plot(x,y)

### Lattice/grid graphics

Library: lattice
library(lattice)xyplot(y~x)

### Grammar of graphics

Library: ggplot2
library(ggplot2)qplot(x,y)

## Racket

Racket has a built-in plotting library

#lang racket(require plot) (define x (build-list 10 values))(define y (list 2.7 2.8 31.4 38.1 58.0 76.2 100.5 130.0 149.3 180.0)) (plot-new-window? #t)(plot (points (map vector x y)))

This opens a new window with this image (with interactive zooming)

And this

#lang racket(require plot) (define x (build-list 10 values))(define y (list 2.7 2.8 31.4 38.1 58.0 76.2 100.5 130.0 149.3 180.0)) (plot-new-window? #t)(plot (lines (map vector x y)))

opens a new window with this image

## REXX

See   Plot coordinate pairs/REXX   for the $PLOT program. ### without point labels Example usage: /*REXX program plots X,Y coördinate pairs of numbers with plain (ASCII) characters.*/x = 0 1 2 3 4 5 6 7 8 9y = 2.7 2.8 31.4 38.1 58.0 76.2 100.5 130.0 149.3 180.0$=                  do j=1  for words(x)           /*build a list suitable for $PLOT subr.*/$=$word(x, j)','word(y, j) /*add this X,Y coördinate to the$ list*/                  end   /*j*/                    /*$≡ 0,2.7 1,2.8 2,31.4 3,38.1 ··· */call '$PLOT'  $/*invoke the REXX program:$PLOT      */exit rc                                          /*stick a fork in it,  we're all done. */
output   when using the default input:
│180                                                                          ∙
│
│
│
│
│
│
│
│                                                                    ∙
│
│
│
│
│                                                            ∙
│
│
│
│
│
│
│                                                   ∙
│
│
│
│
│
│
│                                          ∙
│
│
│
│                                  ∙
│
│
│
│
│                         ∙
│
│                ∙
│
│
│
│
│
│
∙0       ∙                                                                    9
└──────────────────────────────────────────────────────────────────────────────


/*REXX program plots X,Y   coördinate pairs  of  numbers  with plain (ASCII) characters.*/x = 0      1       2       3       4       5        6        7        8        9y = 2.7    2.8    31.4    38.1    58.0    76.2    100.5    130.0    149.3    180.0$= do j=1 for words(x) /*build a list suitable for$PLOT subr.*/                  $=$   word(x, j)','word(y, j)  /*add this X,Y coördinate to the $list*/ end /*j*/ /*$≡ 0,2.7  1,2.8  2,31.4 3,38.1  ···  */call '$PLOT'$   '(LABELDatapoints'             /*invoke the REXX program:  $PLOT */exit rc /*stick a fork in it, we're all done. */ output when using the default input: │180 (9,180)∙ │ │ │ │ │ │ │ │ │ │ ∙(8,149.3) │ │ │ │ │ │ ∙(7,130) │ │ │ │ │ │ │ │ │ │ ∙(6,100.5) │ │ │ │ │ │ │ ∙(5,76.2) │ │ │ │ │ │ ∙(4,58) │ │ │ │ │ │ │ ∙(3,38.1) │ │ ∙(2,31.4) │ │ │ │ │ │ │ │ ∙(0,2.7) ∙(1,2.8) └──────────────────────────────────────────────────────────────────────────────────────────────  ## Ring  # Project : Plot coordinate pairs load "guilib.ring" paint = null new qapp { win1 = new qwidget() { setwindowtitle("Plot coordinate pairs") setgeometry(100,100,1024,900) label1 = new qlabel(win1) { setgeometry(10,10,1024,900) settext("") } new qpushbutton(win1) { setgeometry(50,50,100,30) settext("draw") setclickevent("draw()") } show() } exec() } func draw p1 = new qpicture() color = new qcolor() { setrgb(0,0,255,255) } pen = new qpen() { setcolor(color) setwidth(1) } paint = new qpainter() { begin(p1) setpen(pen) old = 0 yold = 0 xnew = 0 ynew = 0 x2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] y2 = [2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0] for x = 1 to 9 drawline(100*x,720,100*x,0) drawtext(100*x,750,string(x)) next for y = 20 to 180 step 20 drawline(900,4*y,0,4*y) drawtext(0,720-4*y,string(y)) next drawline(0,0,0,720) drawline(0,0,900,0) for i = 1 to 10 if i=1 xold = 100*x2[i] yold = 720-4*y2[i] else xnew = 100*x2[i] ynew = 720-4*y2[i] drawline(xold,yold,xnew,ynew) xold = xnew yold = ynew ok next endpaint() } label1 { setpicture(p1) show() } return  Output: ## Ruby Library: rgplot gnuplot of x,y arrays require 'gnuplot' x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]y = [2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0]Gnuplot.open do |gp| Gnuplot::Plot.new( gp ) do |plot| plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds| ds.with = "linespoints" ds.notitle end endend ## Scala Library: Scala import scala.swing.Swing.pair2Dimensionimport scala.swing.{ MainFrame, Panel, Rectangle }import java.awt.{ Color, Graphics2D, geom } object PlotCoordPairs extends scala.swing.SimpleSwingApplication { //min/max of display-x resp. y val (dx0, dy0) = (70, 30) val (dxm, dym) = (670, 430) val (prefSizeX, prefSizeY) = (720, 480) private def ui = new Panel { import math._ val xmax = { val f1 = pow(10, log10(xs.max).toInt) val f2 = if (f1 < 10) 10 else round(xs.max / f1) * f1 if (f2 >= xs.max) f2 else (round(xs.max / f1) + 1) * f1 } val ymax = { val f1 = pow(10, log10(ys.max).toInt) val f2 = if (f1 < 10) 10 else round(ys.max / f1) * f1 if (f2 >= ys.max) f2 else (round(ys.max / f1) + 1) * f1 } val (xinterv, yinterv) = (xmax / xs.size, ymax / xs.size) case class Coord(x: Double, y: Double) { val (dx, dy) = ((x / xmax * (dxm - dx0) + dx0).toInt, (dym - y / ymax * (dym - dy0)).toInt) } val pcentre = Coord(0, 0) val pxmax = Coord(xmax, 0) val pymax = Coord(0, ymax) background = Color.white preferredSize = (prefSizeX, prefSizeY) //axes: val a_path = new geom.GeneralPath a_path.moveTo(pxmax.dx, pxmax.dy) a_path.lineTo(pcentre.dx, pcentre.dy) //x-axis a_path.lineTo(pymax.dx, pymax.dy) //y-axis // interval ticks: xs.map(i => Coord(i * xinterv, 0)).map(p => { a_path.moveTo(p.dx, p.dy) a_path.lineTo(p.dx, p.dy + 5) }) xs.map(i => Coord(0, i * yinterv)).map(p => { a_path.moveTo(p.dx, p.dy) a_path.lineTo(p.dx - 5, p.dy) }) //grid: val g_path = new geom.GeneralPath (1 to xs.size). map(i => Coord(i * xinterv, 0)).map(p => { g_path.moveTo(p.dx, p.dy); g_path.lineTo(Coord(p.x, ymax).dx, Coord(p.x, ymax).dy) }) (1 to xs.size).map(i => Coord(0, i * yinterv)).map(p => { g_path.moveTo(p.dx, p.dy); g_path.lineTo(Coord(xmax, p.y).dx, Coord(xmax, p.y).dy) }) //labeling: val xlabels = (0 to xs.size).map(i => { val p = Coord(i * xinterv, 0) Triple(p.x.toInt.toString, p.dx - 3, p.dy + 20) }) val ylabels = (0 to xs.size).map(i => { val p = Coord(0, i * yinterv) Triple(p.y.toInt.toString, p.dx - 30, p.dy + 5) }) //curve: val path = new geom.GeneralPath val curve = xs.map(i => Coord(xs(i), ys(i))) path.moveTo(curve.head.dx, curve.head.dy) curve.map(p => path.lineTo(p.dx, p.dy)) //...flag all function values: val rects = curve.map(p => new Rectangle(p.dx - 3, p.dy - 3, 6, 6)) override def paintComponent(g: Graphics2D) = { super.paintComponent(g) g.setColor(Color.lightGray) g.draw(g_path) g.setColor(Color.black) g.draw(a_path) xlabels.map(t => g.drawString(t._1, t._2, t._3)) ylabels.map(t => g.drawString(t._1, t._2, t._3)) g.draw(path) rects.map(g.draw(_)) } } val xs = 0 to 9 val ys: List[Double] = List(2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0) def top = new MainFrame { title = "Rosetta Code >>> Task: Plot coordinate pairs | Language: Scala" contents = ui }} ## Scilab --> x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];--> y = [2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0];--> plot2d(x,y) ## Sidef Translation of: Perl require('GD::Graph::points') var data = [ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0],] var graph = %s'GD::Graph::points'.new(400, 300)var gd = graph.plot(data) var format = 'png'File("qsort-range.#{format}").write(gd.(format), :raw) ## Stata clearinput x y0 2.71 2.82 31.43 38.14 58.05 76.26 100.57 130.08 149.39 180.0end lines y xgraph export image.png ## Tcl Library: Tk Library: Img Screenshot for Tcl code This solution does not use existing plotting packages, but constructs the graphics from bare-metal Tk code. package require Tk # The actual plotting engineproc plotxy {canvas xs ys} { global xfac yfac set maxx [tcl::mathfunc::max {*}$xs]    set maxy [tcl::mathfunc::max {*}$ys] set xfac [expr {[winfo width$canvas] * 0.8/$maxx}] set yfac [expr {[winfo height$canvas] * 0.8/$maxy}] scale$canvas x 0 $maxx$xfac    scale $canvas y 0$maxy $yfac foreach x$xs y $ys { dot$canvas [expr {$x*$xfac}] [expr {$y*$yfac}] -fill red    }}# Rescales the contents of the given canvasproc scale {canvas direction from to fac} {    set f [expr {$from*$fac}]    set t [expr {$to*$fac}]    switch -- $direction { x { set f [expr {$from * $fac}] set t [expr {$to * $fac}]$canvas create line $f 0$t 0            $canvas create text$f 0 -anchor nw -text $from$canvas create text $t 0 -anchor n -text$to         }        y {            set f [expr {$from * -$fac}]            set t [expr {$to * -$fac}]            $canvas create line 0$f 0 $t$canvas create text 0 $f -anchor se -text$from            $canvas create text 0$t -anchor e -text $to } }}# Helper to make points, which are otherwise not a native item typeproc dot {canvas x y args} { set id [$canvas create oval [expr {$x-3}] [expr {-$y-3}] \                [expr {$x+3}] [expr {-$y+3}]]    $canvas itemconfigure$id {*}$args} pack [canvas .c -background white]updateset xs {0 1 2 3 4 5 6 7 8 9}set ys {2.7 2.8 31.4 38.1 58.0 76.2 100.5 130.0 149.3 180.0}plotxy .c$xs $ys.c config -scrollregion [.c bbox all].c move all 20 20 # Save image (this is the only part that requires an external library)package require Imgset im [image create photo -data .c]$im write plotxy.png -format PNG

Of course, if we were generating an encapsulated postscript version, we would be able to do that directly.

Note also that in Tk 8.6, there is no need for an external library to write PNG images; the capability is directly supported.

## TI-89 BASIC

TI-89 screenshot
FnOffPlotsOffNewPlot 1, 1, x, yZoomData

## Ursala

Ursala doesn't plot anything directly, but has libraries to generate LaTeX code for 2D and 3D graphics. The output file has to be run through LaTeX or included into a LaTeX document. Here's the way to do it just as a quick check (all default settings and dots connected with straight lines).

#import std#import flo#import fit#import plo x = <0., 1., 2., 3., 4., 5., 6., 7., 8., 9.>y = <2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0> #output dot'tex' latex_document+ plot main = visualization[curves: <curve[points: ~&p/x y]>]

(output)

Here's one way you might do it if you were interested in publication quality graphics. The dots are connected with a cubic spline interpolating function sampled at 200 points, and the axes are nicely labeled.

main = visualization[   abscissa: axis[      variable: 'problem size',      hats: printf/*'%0.0f' ari10/0. 9.],   ordinates: ~&iNC axis[      variable: 'execution time ($\mu$s)',      hats: printf/*'%0.1f' ari6/0. 180.],   curves: <      curve[         points: ^(~&,[email protected]/x y)* ari200/0. 9.,         attributes: {'linecolor': 'lightgray'}],      curve[         scattered: true,         points: ~&p/x y,         attributes: {'linecolor': 'black'}]>]

(output)

## VBA

Using Excel

Private Sub plot_coordinate_pairs(x As Variant, y As Variant)    Dim chrt As Chart    Set chrt = ActiveSheet.Shapes.AddChart.Chart    With chrt        .ChartType = xlLine        .HasLegend = False        .HasTitle = True        .ChartTitle.Text = "Time"        .SeriesCollection.NewSeries        .SeriesCollection.Item(1).XValues = x        .SeriesCollection.Item(1).Values = y        .Axes(xlValue, xlPrimary).HasTitle = True        .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "microseconds"    End WithEnd SubPublic Sub main()    x = [{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}]    y = [{2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0}]    plot_coordinate_pairs x, yEnd Sub

## XPL0

XPL0 does not provide a library routine for plotting graphs. An issue with this particular task is how general to make the code. This is pretty specific.

Output
include c:\cxpl\codes;          \intrinsic 'code' declarations def     ScrW=640, ScrH=480, VidMode=\$101;def     Sx = ScrW/10,           \pixels per horz grid line        Sy = ScrH/10,           \pixels per vert grid line        Ox = (3+1+1)*8+2,       \offset for horz grid: allow room for "180.0"        Oy = ScrH-20;           \offset for vert grid: allow room for labelsint     X, DataX;real    Y, DataY, Gain;def     Brown=6, LCyan=11; [DataX:= [0,   1,    2,    3,    4,    5,     6,     7,     8,     9]; DataY:= [2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0]; SetVid(VidMode);for X:= 0 to 9 do                                               \draw grid        [Move(X*Sx+Ox, Oy);  Line(X*Sx+Ox, Oy-9*Sy, Brown);     \vert lines         Move(Ox, Oy-X*Sy);  Line(9*Sx+Ox, Oy-X*Sy, Brown);     \horz lines        ];Format(3,1);  Attrib(LCyan);                                    \label gridY:= 0.0;for X:= 0 to 9 do        [Move(X*Sx+Ox-3, Oy+6); IntOut(6, X);                   \X axis         Move(0, Oy-X*Sy-7);     RlOut(6, Y);                   \Y axis        Y:= Y + 20.0;        ];Gain:= float(Sy)/20.0;Move(DataX(0)*Sx+Ox, Oy-Fix(DataY(0)*Gain));                    \plot pointsfor X:= 1 to 9 do        Line(DataX(X)*Sx+Ox, Oy-Fix(DataY(X)*Gain), LCyan); if ChIn(1) then [];                                             \wait for keySetVid(3);                                                      \restore text]

## Yorick

x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];y = [2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0];window, 0;plmk, y, x;window, 1;plg, y, x, marks=0;

## zkl

Translation of: gnuplot
Translation of: Go

Solution using gnuplot. Output is the same as for the gnuplot example on this page.

A program can of course supply commands and data to gnuplot as prepared files. For the spirit of controlling plotting with the native language however, this example shows how commands and data can be prepared programmatically and supplied to gnuplot through stdin.

#<<<cmd:=0'|#set term wxt  # X11unset key  # Only one data set, so the key is uninformative plot '-'   # '-' can be replaced with a filename, to read data from that file.  0   2.7  1   2.8  2  31.4  3  38.1  4  68.0  5  76.2  6 100.5  7 130.0  8 149.3  9 180.0e|;#<<< gnuplot:=System.popen("gnuplot","w");gnuplot.write(cmd); gnuplot.flush();ask("Hit return to finish"); gnuplot.close();