I'm working on modernizing Rosetta Code's infrastructure. Starting with communications. Please accept this time-limited open invite to RC's Slack.. --Michael Mol (talk) 20:59, 30 May 2020 (UTC)

# Plot coordinate pairs

(Redirected from Plot x, y arrays)
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.

## AArch64 Assembly

Works with: as version Raspberry Pi 3B version Buster 64 bits
 /* ARM assembly AARCH64 Raspberry PI 3B *//*  program areaPlot64.s   */ /*******************************************//* Constantes file                         *//*******************************************//* for this file see task include a file in language AArch64 assembly*/.include "../includeConstantesARM64.inc".equ HAUTEUR, 22.equ LARGEUR, 50.equ MARGEGAUCHE, 10 /*******************************************//* Structures                               *//********************************************//* structure  for points  */    .struct  0point_posX:    .struct  point_posX + 8 point_posY:    .struct  point_posY + 8 point_end:/*******************************************//* Initialized data                        *//*******************************************/.dataszMessError:        .asciz "Number of points too large !! \n"szCarriageReturn:  .asciz "\n"szMessMovePos:      .ascii "\033["          // cursor positionposY:                .byte '0'                     .byte '6'                    .ascii ";"posX:                .byte '0'                     .byte '3'                    .asciz "H*"szMessEchelleX:     .asciz  "Y^ X="szClear1:                  .byte 0x1B                            .byte 'c'        // other console clear                           .byte 0szMessPosEch:      .ascii "\033["           // scale cursor positionposY1:                .byte '0'                     .byte '0'                    .ascii ";"posX1:                .byte '0'                     .byte '0'                    .asciz "H" //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}; /* areas points  */tbPoints:   .quad 0      // 1            .quad 27     //    Data * 10 for integer operation            .quad 1      // 2            .quad 28            .quad 2      // 3            .quad 314            .quad 3      // 4            .quad 381            .quad 4      // 5            .quad 580            .quad 5      // 6            .quad 762            .quad 6      // 7            .quad 1005            .quad 7      // 8            .quad 1300            .quad 8      // 9            .quad 1493            .quad 9      // 10            .quad 1800/*******************************************//* UnInitialized data                      *//*******************************************/.bsssZoneConv:       .skip 30/*******************************************//*  code section                           *//*******************************************/.text.global main main:                      // entry of program    ldr x0,qAdrtbPoints    // area address    mov x1,10              // size    mov x2,LARGEUR    mov x3,HAUTEUR    bl plotArea    b 100f 100:                       // standard end of the program    mov x0,  0             // return code    mov x8,EXIT            // request to exit program    svc 0                  // perform the system call qAdrsZoneConv:          .quad sZoneConvqAdrszCarriageReturn:   .quad szCarriageReturnqAdrtbPoints:           .quad tbPoints/************************************/       /* create graph                     *//************************************/      /* x0 contains area points address *//* x1 contains number points *//* x2 contains graphic weight  *//* x3 contains graphic height  *//* REMARK : no save x9-x20  registers */plotArea:    stp x2,lr,[sp,-16]!         // save  registers    stp x3,x4,[sp,-16]!         // save  registers    cmp x1,x2    bge 99f    mov x9,x0    mov x4,x1    ldr x10,qAdrposX    ldr x11,qAdrposY    mov x12,#0                   // indice    mov x13,point_end            // element area size     mov x17,0                    // Y maxi    mov x19,-1                   // Y Mini1:                               //search mini maxi     madd x14,x12,x13,x0          // load coord Y    ldr x15,[x14,point_posY]    cmp x15,x17    csel x17,x15,x17,hi          // maxi ?    cmp x15,x19    csel x19,x15,x19,lo          // mini ?    add x12,x12,#1    cmp x12,x1                   // end ?    blt 1b                       // no -> loop                                 // compute ratio    udiv x15,x17,x3              // ratio = maxi / height    add x15,x15,1                // for adjust    ldr x0,qAdrszClear1          // clear screen    bl affichageMess    udiv x20,x2,x4               // compute interval X = weight / number points    mov x12,0                    // indice2:                               // loop begin for display point    madd x14,x12,x13,x9          // charge X coord point     ldr x16,[x14,point_posX]    mul x16,x20,x12              // interval * indice    add x0,x16,MARGEGAUCHE       // + left margin    mov x1,x10                   // conversion ascii and store    bl convPos     ldr x18,[x14,point_posY]              // charge Y coord point    udiv x18,x18,x15             // divide by ratio    sub x0,x3,x18                // inversion position ligne    mov x1,x11                   // conversion ascii and store    bl convPos     ldr x0,qAdrszMessMovePos     // display * at position X,Y    bl affichageMess    add x12,x12,1                // next point     cmp x12,x4                   // end ?    blt 2b                       // no -> loop                                 // display left scale                                 // display Y Mini    mov x0,0    ldr x1,qAdrposX1    bl convPos    mov x0,HAUTEUR    ldr x1,qAdrposY1    bl convPos    ldr x0,qAdrszMessPosEch    bl affichageMess    mov x0,x19    ldr x1,qAdrsZoneConv    bl conversion10    ldr x0,qAdrsZoneConv    bl affichageMess                                 // display Y Maxi    mov x0,0    ldr x1,qAdrposX1    bl convPos    mov x0,0    ldr x1,qAdrposY1    bl convPos    ldr x0,qAdrszMessPosEch    bl affichageMess    mov x0,x17    ldr x1,qAdrsZoneConv    bl conversion10    ldr x0,qAdrsZoneConv    bl affichageMess                                 // display average value    mov x0,0    ldr x1,qAdrposX1    bl convPos    mov x0,HAUTEUR/2    add x0,x0,#1    ldr x1,qAdrposY1    bl convPos    ldr x0,qAdrszMessPosEch    bl affichageMess    lsr x0,x17,#1    ldr x1,qAdrsZoneConv    bl conversion10    ldr x0,qAdrsZoneConv    bl affichageMess                                 // display X scale    mov x0,0    ldr x1,qAdrposX1    bl convPos    mov x0,HAUTEUR+1    ldr x1,qAdrposY1    bl convPos    ldr x0,qAdrszMessPosEch    bl affichageMess    ldr x0,qAdrszMessEchelleX    bl affichageMess      mov x12,0                       // indice    mov x19,MARGEGAUCHE10:    udiv x20,x2,x4    madd x0,x20,x12,x19    ldr x1,qAdrposX1    bl convPos    mov x0,HAUTEUR+1    ldr x1,qAdrposY1    bl convPos    ldr x0,qAdrszMessPosEch    bl affichageMess    madd x14,x12,x13,x9             // load X coord point     ldr x0,[x14,point_posX]    ldr x1,qAdrsZoneConv    bl conversion10    ldr x0,qAdrsZoneConv    bl affichageMess    add x12,x12,1    cmp x12,x4    blt 10b     ldr x0,qAdrszCarriageReturn    bl affichageMess     mov x0,0                    // return code    b 100f99:                             // error     ldr x0,qAdrszMessError    bl affichageMess    mov x0,-1                   // return code100:    ldp x3,x4,[sp],16           // restaur  2 registers    ldp x2,lr,[sp],16           // restaur  2 registers    ret                         // return to address lr x30qAdrszMessMovePos:         .quad szMessMovePosqAdrszClear1:              .quad szClear1qAdrposX:                  .quad posXqAdrposY:                  .quad posYqAdrposX1:                 .quad posX1qAdrposY1:                 .quad posY1qAdrszMessEchelleX:        .quad szMessEchelleXqAdrszMessPosEch:          .quad szMessPosEchqAdrszMessError:           .quad szMessError/************************************/       /* conv position in ascii and store at address *//************************************/      /* x0 contains position *//* x1 contains string address */convPos:    stp x2,lr,[sp,-16]!      // save  registers    stp x3,x4,[sp,-16]!      // save  registers    mov x2,10    udiv x3,x0,x2    add x4,x3,48             // convert in ascii    strb w4,[x1]             // store posX    msub x4,x3,x2,x0    add x4,x4,48    strb w4,[x1,1]100:    ldp x3,x4,[sp],16        // restaur  2 registers    ldp x2,lr,[sp],16        // restaur  2 registers    ret                      // return to address lr x30/********************************************************//*        File Include fonctions                        *//********************************************************//* for this file see task include a file in language AArch64 assembly */.include "../includeARM64.inc"
Output:
1800                                                  *

*

*

*

900
*

*

*
*

27       *    *
Y^ X=    0    1    2    3    4    5    6    7    8    9



## EasyLang

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 ]# clearlinewidth 0.5move 10 3line 10 95line 95 95textsize 3n = len x[]m = 0for i range n  m = higher y[i] m.linewidth 0.1sty = m div 9for i range 10  move 2 94 - i * 10  text i * sty  move 10 95 - i * 10  line 95 95 - i * 10.stx = x[n - 1] div 9for i range 10  move i * 9 + 10 96.5  text i * stx  move i * 9 + 10 95  line i * 9 + 10 3.color 900linewidth 0.5for i range n  x = x[i] * 9 / stx + 10  y = 100 - (y[i] / sty * 10 + 5)  if i = 0    move x y  else    line x y  ..

## 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))

## Factor

Works with: Factor version 0.99 2019-01-23
USING: accessors assocs colors.constants kernel sequences uiui.gadgets ui.gadgets.charts ui.gadgets.charts.lines ; chart new { { 0 9 } { 0 180 } } >>axesline new COLOR: blue >>color9 <iota> { 2.7 2.8 31.4 38.1 58 76.2 100.5 130 149.3 180 } zip>>data add-gadget "Coordinate pairs" open-window

## Fōrmulæ

Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation —i.e. XML, JSON— they are intended for storage and transfer purposes more than visualization and edition.

Programs in Fōrmulæ are created/edited online in its website, However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.

## FreeBASIC

Translation of: Liberty BASIC

### Text mode

Dim As Integer i, x(9), y(9)For i = 0 To 9    x(i) = iNext i y(0) = 2.7y(1) = 2.8y(2) = 31.4y(3) = 38.1y(4) = 58.0y(5) = 76.2y(6) = 100.5y(7) = 130.0y(8) = 149.3y(9) = 180.0 Locate 22, 4For i = 0 To 9    Locate 22, ((i * 4) + 2) : Print iNext i For i = 0 To 20 Step 2    Locate (21 - i), 0 : Print (i * 10)Next i Color 14For i = 0 To 9    Locate (21 - (y(i)/ 10)), (x(i) * 4) + 2 : Print "."Next iSleep

## 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

## Processing

 //Aamrun, 26th June 2022 int x[] = {0,   1,    2,    3,    4,    5,     6,     7,     8,     9};float y[] = {2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0}; size(300,300);surface.setTitle("Rosetta Plot"); stroke(#ff0000); for(int i=0;i<x.length;i++){  ellipse(x[i],y[i],3,3);}

## Phix

Library: Phix/pGUI

Output same as BBC BASIC, you can run this online here.

--
-- demo\rosetta\Plot_coordinate_pairs.exw
-- ======================================
--
with javascript_semantics
include pGUI.e
include IupGraph.e

constant 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}

function get_data(Ihandle graph) return {{x,y,CD_BLUE}} end function

IupOpen()
Ihandle graph = IupGraph(get_data),
dlg = IupDialog(graph,TITLE="Plot coordinate pairs")
IupSetAttributes(dlg,"RASTERSIZE=320x240,MINSIZE=320x200")
IupSetAttributes(graph,"XTICK=1,XMIN=0,XMAX=9")
IupSetAttributes(graph,"YTICK=20,YMIN=0,YMAX=180")
IupShow(dlg)
if platform()!=JS then
IupMainLoop()
IupClose()
end if


## PicoLisp

Example picoLisp output
(load "@lib/ps.l") (scl 1) (de plot (PsFile DX DY Lst)   (let (SX (length Lst)  SY (apply max Lst)  N 0 Val)      (out PsFile         (psHead (+ DX 20) (+ DY 40))         (font (9 . "Helvetica"))         (if (or (=0 SX) (=0 SY))            (window 60 12 DX DY               (font 24 ,"Not enough Data") )            (setq Lst  # Build coordinates               (let X -1                  (mapcar                     '((Y)                        (cons                           (*/ (inc 'X) DX SX)                           (- DY (*/ Y DY SY)) ) )                     Lst ) ) )            (color 55 95 55  # Background color               (let (X (+ DX 40) Y (+ DY 40))                  (poly T  0 0  X 0  X Y  0 Y  0 0) ) )            (window 20 20 DX DY  # Plot coordinates               (poly NIL 0 0  0 DY  (- DX 20) DY)               (color 76 24 24                  (poly NIL (caar Lst) (cdar Lst) (cdr Lst)) ) )            (window 4 4 60 12 (ps (format SY *Scl)))            (for X SX               (window (+ 6 (*/ (dec X) DX SX)) (+ 24 DY) 30 12                  (ps (format (dec X)) 0) ) ) )         (page) ) ) ) (plot "plot.ps" 300 200 (2.7 2.8 31.4 38.1 58.0 76.2 100.5 130.0 149.3 180.0))(call 'display "plot.ps")

## PostScript

 /x [0 1 2 3 4 5 6 7 8 9] def/y [2.7 2.8 31.4 38.1 58.0 76.2 100.5 130.0 149.3 180.0] def/i 1 def newpathx 0 get y 0 get movetox length 1 sub{x i get y i get lineto/i i 1 add def}repeatstroke

## PureBasic

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 └──────────────────────────────────────────────────────────────────────────────  ### with point labels /*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.

## 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();