Plot coordinate pairs: Difference between revisions
m
→{{header|EasyLang}}
m (→Plotinum: fix image?) |
|||
(79 intermediate revisions by 33 users not shown) | |||
Line 1:
{{task}}
;Task:
Plot a function represented as <big><big> x, y </big></big> numerical arrays.
Post the resulting image for the following input arrays (taken from [[Time_a_function#Python|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]].
<br><br>
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
/* 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 0
point_posX:
.struct point_posX + 8
point_posY:
.struct point_posY + 8
point_end:
/*******************************************/
/* Initialized data */
/*******************************************/
.data
szMessError: .asciz "Number of points too large !! \n"
szCarriageReturn: .asciz "\n"
szMessMovePos: .ascii "\033[" // cursor position
posY: .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 0
szMessPosEch: .ascii "\033[" // scale cursor position
posY1: .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 */
/*******************************************/
.bss
sZoneConv: .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 sZoneConv
qAdrszCarriageReturn: .quad szCarriageReturn
qAdrtbPoints: .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 Mini
1: //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 // indice
2: // 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,MARGEGAUCHE
10:
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 100f
99: // error
ldr x0,qAdrszMessError
bl affichageMess
mov x0,-1 // return code
100:
ldp x3,x4,[sp],16 // restaur 2 registers
ldp x2,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
qAdrszMessMovePos: .quad szMessMovePos
qAdrszClear1: .quad szClear1
qAdrposX: .quad posX
qAdrposY: .quad posY
qAdrposX1: .quad posX1
qAdrposY1: .quad posY1
qAdrszMessEchelleX: .quad szMessEchelleX
qAdrszMessPosEch: .quad szMessPosEch
qAdrszMessError: .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"
</syntaxhighlight>
{{Output}}
<pre>
1800 *
*
*
*
900
*
*
*
*
27 * *
Y^ X= 0 1 2 3 4 5 6 7 8 9
</pre>
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
<syntaxhighlight lang="action!">INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
DEFINE PTR="CARD"
DEFINE BUF_SIZE="100"
DEFINE REAL_SIZE="3"
TYPE Settings=[
INT xMin,xMax,xStep,yMin,yMax,yStep
INT xLeft,xRight,yTop,yBottom
INT tickLength]
BYTE ARRAY xs(BUF_SIZE),ys(BUF_SIZE)
BYTE count=[0]
PTR FUNC GetXPtr(BYTE i)
RETURN (xs+3*i)
PTR FUNC GetYPtr(BYTE i)
RETURN (ys+3*i)
PROC AddPoint(CHAR ARRAY xstr,ystr)
REAL POINTER p
p=GetXPtr(count) ValR(xstr,p)
p=GetYPtr(count) ValR(ystr,p)
count==+1
RETURN
PROC InitData()
AddPoint("0.0","2.7")
AddPoint("1.0","2.8")
AddPoint("2.0","31.4")
AddPoint("3.0","38.1")
AddPoint("4.0","58.0")
AddPoint("5.0","76.2")
AddPoint("6.0","100.5")
AddPoint("7.0","130.0")
AddPoint("8.0","149.3")
AddPoint("9.0","180.0")
RETURN
INT FUNC GetXPos(Settings POINTER s INT x)
INT res
res=x*(s.xRight-s.xLeft)/(s.xMax-s.xMin)+s.xLeft
RETURN (res)
INT FUNC GetYPos(Settings POINTER s INT y)
INT res
res=y*(s.yTop-s.yBottom)/(s.yMax-s.yMin)+s.yBottom
RETURN (res)
INT FUNC GetXPosR(Settings POINTER s REAL POINTER x)
REAL nom,denom,div,tmp
INT res
IntToReal(s.xRight-s.xLeft,tmp)
RealMult(tmp,x,nom)
IntToReal(s.xMax-s.xMin,denom)
RealDiv(nom,denom,div)
res=RealToInt(div)+s.xLeft
RETURN (res)
INT FUNC GetYPosR(Settings POINTER s REAL POINTER y)
REAL nom,denom,div,tmp
INT res
IntToReal(s.yBottom-s.yTop,tmp)
RealMult(tmp,y,nom)
IntToReal(s.yMax-s.yMin,denom)
RealDiv(nom,denom,div)
res=-RealToInt(div)+s.yBottom
RETURN (res)
BYTE FUNC AtasciiToInternal(CHAR c)
BYTE c2
c2=c&$7F
IF c2<32 THEN
RETURN (c+64)
ELSEIF c2<96 THEN
RETURN (c-32)
FI
RETURN (c)
PROC CharOut(INT x,y CHAR c)
BYTE i,j,v
PTR addr
addr=$E000+AtasciiToInternal(c)*8;
FOR j=0 TO 7
DO
v=Peek(addr)
i=8
WHILE i>0
DO
IF v&1 THEN
Plot(x+i,y+j)
FI
v=v RSH 1
i==-1
OD
addr==+1
OD
RETURN
PROC TextOut(INT x,y CHAR ARRAY text)
BYTE i
FOR i=1 TO text(0)
DO
CharOut(x,y,text(i))
x==+8
OD
RETURN
PROC DrawAxes(Settings POINTER s)
INT i,x,y
CHAR ARRAY t(10)
Plot(s.xLeft,s.yTop)
DrawTo(s.xLeft,s.yBottom)
DrawTo(s.xRight,s.yBottom)
FOR i=s.xMin TO s.xMax STEP s.xStep
DO
x=GetXPos(s,i)
Plot(x,s.yBottom)
DrawTo(x,s.yBottom+s.tickLength)
StrI(i,t)
TextOut(x-t(0)*4,s.yBottom+s.tickLength+1,t)
OD
FOR i=s.yMin TO s.yMax STEP s.yStep
DO
y=GetYPos(s,i)
Plot(s.xLeft-s.tickLength,y)
DrawTo(s.xLeft,y)
StrI(i,t)
TextOut(s.xLeft-s.tickLength-1-t(0)*8,y-4,t)
OD
RETURN
PROC DrawPoint(INT x,y)
Plot(x-1,y-1) DrawTo(x+1,y-1)
DrawTo(x+1,y+1) DrawTo(x-1,y+1)
DrawTo(x-1,y-1)
RETURN
PROC DrawSeries(Settings POINTER s)
INT i,x,y,prevX,prevY
REAL POINTER p
FOR i=0 TO count-1
DO
p=GetXPtr(i) x=GetXPosR(s,p)
p=GetYPtr(i) y=GetYPosR(s,p)
DrawPoint(x,y)
IF i>0 THEN
Plot(prevX,prevY)
DrawTo(x,y)
FI
prevX=x prevY=y
OD
RETURN
PROC DrawPlot(Settings POINTER s)
DrawAxes(s)
DrawSeries(s)
RETURN
PROC Main()
BYTE CH=$02FC,COLOR1=$02C5,COLOR2=$02C6
Settings s
Graphics(8+16)
Color=1
COLOR1=$0C
COLOR2=$02
InitData()
s.xMin=0 s.xMax=9 s.xStep=1
s.yMin=0 s.yMax=180 s.yStep=20
s.xLeft=30 s.xRight=311 s.yTop=8 s.yBottom=177
s.tickLength=3
DrawPlot(s)
DO UNTIL CH#$FF OD
CH=$FF
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Plot_coordinate_pairs.png Screenshot from Atari 8-bit computer]
=={{header|Ada}}==
Line 13 ⟶ 526:
{{libheader|GtkAda}}
[[Image:Gtkada_plot.png|thumb|right|100px|Example GtkAda plot]]
<
with Gtk.Main;
with Gtk.Window; use Gtk.Window;
Line 60 ⟶ 573:
Gtk.Main.Main;
end PlotCoords;
</syntaxhighlight>
=={{header|ALGOL 68}}==
{{works with|ALGOL 68|Revision 1 - extensions to standard used - PRAGMA READ and Currying}}
Line 66 ⟶ 580:
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format'''[ted] ''transput''.}}
[[Image:Plot_coordinate_pairs-Algol68.gif|thumb|right|100px|Example Algol68 plot]]
'''File: Plot_coordinate_pairs.a68'''<
# -*- coding: utf-8 -*- #
Line 102 ⟶ 616:
);
PR READ "postlude/exception.a68" PR</
=={{header|AutoHotkey}}==
Line 108 ⟶ 622:
{{works with|AutoHotkey_L}}(AutoHotkey1.1+)
{{libheader|GDIP}}
<
#NoEnv
SetBatchLines, -1
Line 176 ⟶ 690:
Exit:
Gdip_Shutdown(pToken)
ExitApp</
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
[[Image:Coordinate_pair_bbc.gif|right]]
<
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
Line 209 ⟶ 723:
DRAW 100*x(i%),4*y(i%)
ENDIF
NEXT</
=={{header|C}}==
Line 216 ⟶ 730:
{{libheader|libplot}}
<
#include <stdlib.h>
#include <math.h>
Line 332 ⟶ 846:
pl_flushpl();
pl_closepl();
}</
No one would use the previous code to produce a plot (that looks [http://i40.tinypic.com/f2t0l0.png this way]; instead, normally we produce data through a program, then we plot the data using e.g. [[Plot x, y arrays#gnuplot|gnuplot]] or other powerful tools; the result (with gnuplot and without enhancement) could look [http://i41.tinypic.com/2qivbsn.png like this] instead.
Line 338 ⟶ 852:
===Writing EPS===
[[File:plot-2d-c.png|center]]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 <math.h>
#include <string.h>
Line 468 ⟶ 982:
plot(x, y, N, "r-o");
return 0;
}</
=={{header|C++}}==
[[File:plot_cpp.png|300px]]
<
#include <windows.h>
#include <string>
Line 696 ⟶ 1,210:
}
//--------------------------------------------------------------------------------------------------
</syntaxhighlight>
=={{header|Clojure}}==
{{libheader|incanter}}
<
(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))
</syntaxhighlight>
{{Out}}
[http://i.imgur.com/0RQaxNl.png]
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
{{libheader| Boost.Process}}
{{Trans|Go}}
Boost.Process is part of [https://github.com/MaiconSoft/DelphiBoostLib DelphiBoostLib].
<syntaxhighlight lang="delphi">
program Plot_coordinate_pairs;
{$APPTYPE CONSOLE}
uses
System.SysUtils,
Boost.Process;
var
x: TArray<Integer>;
y: TArray<Double>;
begin
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];
var plot := TPipe.Create('gnuplot -p', True);
plot.WriteA('unset key; plot ''-'''#10);
for var i := 0 to High(x) do
plot.WriteA(format('%d %f'#10, [x[i], y[i]]));
plot.writeA('e'#10);
writeln('Press enter to close');
Readln;
plot.Kill;
plot.Free;
readln;
end.</syntaxhighlight>
=={{header|EasyLang}}==
[https://easylang.online/show/#cod=hVBBasMwELzrFQO9taBKVhxbh/YjRoeQKK3AlsEWqdzXd1dx2iQt1GCYndndWU3uHF7QQUGjgsEGNbZo0MLCiWVVK9nQ38JouYFppUbdSoVmKytopWQNbRQRemOlgW4ZO/EAse/9bhJ9iP4jHNI7qFUM48nTFGxTBIb1GdmaUPI5zeHTw4hI5r2PyJ0TA2EljuOEQEgjjYgCQDhi6YLDKwYu6eNOpriUQt64azGnhfQBh3CCXfdNu/jm6XrFI5fzajyR9Liy3/fdsKW3otCuSX5AKcmK7OeUyTB30f3jySOWNpU8LpZXJOX1R6u+s8xkuR978rBK3SX/O73zaRQf73vm8bKVpWWNsdBLeR1pP5dl8OvEFw== Run it]
<syntaxhighlight>
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 ]
#
clear
linewidth 0.5
move 10 97
line 10 5
line 95 5
textsize 3
n = len x[]
m = 0
for i = 1 to n
if y[i] > m
m = y[i]
.
.
linewidth 0.1
sty = m div 9
for i range0 10
move 10 5 + i * 10
line 95 5 + i * 10
move 2 4 + i * 10
text i * sty
.
stx = x[n] div 9
for i range0 10
move i * 9 + 10 5
line i * 9 + 10 97
move i * 9 + 10 1
text i * stx
.
color 900
linewidth 0.5
for i = 1 to n
x = x[i] * 9 / stx + 10
y = y[i] / sty * 10 + 5
line x y
.
</syntaxhighlight>
=={{header|EchoLisp}}==
Resulting image [http://www.echolalie.org/echolisp/images/plot-coordinates.png here].
<
(lib 'plot)
Line 721 ⟶ 1,313:
(plot-grid 1 20)
(plot-text " Rosetta plot coordinate pairs" 0 10 "white")
</syntaxhighlight>
=={{header|Erlang}}==
Using [https://github.com/psyeugenic/eplot Eplot] to produce PNG.
<syntaxhighlight lang="erlang">
-module( plot_coordinate_pairs ).
Line 740 ⟶ 1,331:
PNG = egd_chart:graph( [{File, lists:zip(Xs, Ys)}] ),
file:write_file( File ++ ".png", PNG ).
</syntaxhighlight>
The result looks like [https://github.com/ebengt/rosettacode/blob/master/graphs/plot_coordinate_pairs.png this].
Line 747 ⟶ 1,338:
Using the [http://www.ffconsultancy.com/products/fsharp_for_visualization/ F# for Visualization] library:
[[Image:FSViz.png|300px|thumb|right|alt text]]
<
let x = Seq.map float [|0; 1; 2; 3; 4; 5; 6; 7; 8; 9|]
Line 754 ⟶ 1,345:
open FlyingFrog.Graphics
Plot([Data(Seq.zip x y)], (0.0, 9.0))</
=={{header|Factor}}==
{{works with|Factor|0.99 2019-01-23}}
<syntaxhighlight lang="factor">USING: accessors assocs colors.constants kernel sequences ui
ui.gadgets ui.gadgets.charts ui.gadgets.charts.lines ;
chart new { { 0 9 } { 0 180 } } >>axes
line new COLOR: blue >>color
9 <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</syntaxhighlight>
=={{header|Fōrmulæ}}==
{{FormulaeEntry|page=https://formulae.org/?script=examples/Plot_coordinate_pairs}}
'''Solution'''
[[File:Fōrmulæ - Plot coordinate pairs 01.png]]
[[File:Fōrmulæ - Plot coordinate pairs 02.png]]
=={{header|FreeBASIC}}==
{{trans|Liberty BASIC}}
===Text mode===
<syntaxhighlight lang="freebasic">Dim As Integer i, x(9), y(9)
For i = 0 To 9
x(i) = i
Next i
y(0) = 2.7
y(1) = 2.8
y(2) = 31.4
y(3) = 38.1
y(4) = 58.0
y(5) = 76.2
y(6) = 100.5
y(7) = 130.0
y(8) = 149.3
y(9) = 180.0
Locate 22, 4
For i = 0 To 9
Locate 22, ((i * 4) + 2) : Print i
Next i
For i = 0 To 20 Step 2
Locate (21 - i), 0 : Print (i * 10)
Next i
Color 14
For i = 0 To 9
Locate (21 - (y(i)/ 10)), (x(i) * 4) + 2 : Print "."
Next i
Sleep</syntaxhighlight>
=={{header|gnuplot}}==
[[Image:Plotxy-gnuplot.png|thumb|right|200px|Example gnuplot output]]
<
plot '-' # '-' can be replaced with a filename, to read data from that file.
Line 771 ⟶ 1,417:
8 149.3
9 180.0
e</
<br clear=right>
Line 780 ⟶ 1,426:
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.
<
import (
Line 809 ⟶ 1,455:
w.Close()
g.Wait()
}</
===
{{libheader|
[[File:GoPoints.png|right|Go plot]]
<
import (
Line 844 ⟶ 1,490:
log.Fatal(err)
}
}</
=={{header|Groovy}}==
Line 850 ⟶ 1,496:
[[File:GroovyPlotDemo.png|300px|thumb|right|Screenshot of groovy solution]]
<
import javax.swing.JFrame
import org.jfree.chart.ChartFactory
Line 877 ⟶ 1,523:
widget(chart())
}
}</
=={{header|Haskell}}==
gnuplot is a package from [http://hackage.haskell.org/packages/hackage.html HackageDB].
<
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)</
=={{header|HicEst}}==
<
x = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
Line 896 ⟶ 1,542:
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)</
[[File:HicEst_plot_coordinate_pairs.png]]
=={{header|Icon}} and {{header|Unicon}}==
[[File:Plotpoints-unicon.gif|thumb|right|Sample Output]]
<
procedure main()
Line 986 ⟶ 1,632:
every q[i := 1 to *q] := pix - q[i]
return P
end</
{{libheader|Icon Programming Library}}
Line 994 ⟶ 1,640:
=={{header|J}}==
{{libheader|plot}}
<
X=: i.10
Y=: 2.7 2.8 31.4 38.1 58.0 76.2 100.5 130.0 149.3 180.0
'dot; pensize 2.4' plot X;Y</
[http://www.jsoftware.com/jwiki/RosettaCode/ExamplePlot1 Output of plot.]
Line 1,005 ⟶ 1,651:
=={{header|Java}}==
<
import java.awt.event.*;
import java.awt.geom.*;
Line 1,094 ⟶ 1,740:
}
}
</syntaxhighlight>
=={{header|jq}}==
Using R (non-interactive mode)
Line 1,100 ⟶ 1,747:
jq is designed to interoperate with other tools, and in this section we illustrate how jq can be used with R in a simple pipeline: jq will produce a stream of CSV data that will be piped into R operating in non-interactive mode. Assuming the jq and R programs are respectively in plot.jq and plot.R, the pipeline would look like this:
<
The above would produce the plot as a .pdf file.
'''plot.jq'''
<
# if your version of jq includes transpose as a builtin.
#
Line 1,123 ⟶ 1,770:
def plot(x;y): "A,B", ( [x,y] | transpose | map( @csv ) | .[]);
plot(x;y)</
'''plot.R'''
<
x = mydata$A # x-axis
Line 1,132 ⟶ 1,779:
main="Scatterplot Example",
xlab="x-axis label", # x-axis label
ylab="y-axis label" ) # y-axis label</
=={{header|Julia}}==
Using
<syntaxhighlight lang="julia">using Plots
plotlyjs()
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]
p = scatter(x, y)
savefig(p, "/tmp/testplot.png")</syntaxhighlight>
=={{header|Kotlin}}==
{{libheader|JFreeChart}}
{{trans|Groovy}}
<syntaxhighlight lang="scala">// Version 1.2.31
import org.jfree.chart.ChartFactory
import org.jfree.chart.ChartPanel
import org.jfree.data.xy.XYSeries
import org.jfree.data.xy.XYSeriesCollection
import org.jfree.chart.plot.PlotOrientation
import javax.swing.JFrame
import javax.swing.SwingUtilities
import java.awt.BorderLayout
fun main(args: Array<String>) {
val x = intArrayOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
val y = doubleArrayOf(
2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0
)
val series = XYSeries("plots")
(0 until x.size).forEach { series.add(x[it], y[it]) }
val labels = arrayOf("Plot Demo", "X", "Y")
val data = XYSeriesCollection(series)
val options = booleanArrayOf(false, true, false)
val orient = PlotOrientation.VERTICAL
val chart = ChartFactory.createXYLineChart(
labels[0], labels[1], labels[2], data, orient, options[0], options[1], options[2]
)
val chartPanel = ChartPanel(chart)
SwingUtilities.invokeLater {
val f = JFrame()
with(f) {
defaultCloseOperation = JFrame.EXIT_ON_CLOSE
add(chartPanel, BorderLayout.CENTER)
title = "Plot coordinate pairs"
isResizable = false
pack()
setLocationRelativeTo(null)
isVisible = true
}
}
}</syntaxhighlight>
{{out}}
<pre>
Similar to Groovy entry.
</pre>
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
1) define X & Y:
{def X 0 1 2 3 4 5 7 8 9}
-> X
{def Y 2.7 2.8 31.4 38.1 58.0 76.2 100.5 130.0 149.3 180.0}
-> Y
2) define a function returning a sequence of SVG points
{def curve
{lambda {:curve :kx :ky}
{S.map {{lambda {:curve :kx :ky :i}
{* :kx {S.get :i {{car :curve}}}}
{* :ky {S.get :i {{cdr :curve}}}} } :curve :kx :ky}
{S.serie 0 {- {S.length {X}} 1}} }}}
3) draw a polyline in a SVG context
{svg {@ width="580" height="300" style="background:#eee"}
{g {AXES 580 300}
{polyline {@ points="{curve {cons X Y} 30 0.9}"
stroke="#000" fill="transparent" stroke-width="1"}} }}
where
{def AXES
{lambda {:w :h}
{@ transform="translate({/ :w 2},{/ :h 2}) scale(1,-1)"}
{line {@ x1="-{/ :w 2}:w" y1="0"
x2="{/ :w 2}" y2="0"
stroke="red" fill="transparent"}}
{line {@ x1="0" y1="-{/ :h 2}"
x2="0" y2="{/ :h 2}"
stroke="green" fill="transparent"}} }}
4) the result can be seen in http://lambdaway.free.fr/lambdawalks/?view=plot4
</syntaxhighlight>
=={{header|Liberty BASIC}}==
First version writes directly to LB's console window.
<syntaxhighlight lang="lb">
'Plotting coordinate pairs MainWin - Style
For i = 0 To 9
Line 1,182 ⟶ 1,918:
End
</syntaxhighlight>
The second version uses the more typical graphic window approach, and is written to enable easy adaptation to other data sets.
<syntaxhighlight lang="lb">
nomainwin
Line 1,248 ⟶ 1,984:
sy = offsetY-y*scaleY 'y is inverted
end function
</syntaxhighlight>
[http://www.diga.me.uk/PlotCoordPairs.gif LB screen]
=={{header|LiveCode}}==
Displaying the plot with vector graphics
<syntaxhighlight lang="livecode">
on plotGraphic
local tCoordinates
local x = "0, 1, 2, 3, 4, 5, 6, 7, 8, 9"
local y = "2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0"
if there is a graphic "graph" then delete graphic "graph"
repeat with i = 1 to the number of items of x
put item i of x into item 1 of line i of tCoordinates
put item i of y into item 2 of line i of tCoordinates
end repeat
create graphic "graph"
set the style of graphic "graph" to "polygon"
set the points of graphic "graph" to tCoordinates
repeat with i = 1 to the number of lines of tCoordinates
put the top of grc "graph" + the height of grc "graph" - item 2 of line i of tCoordinates into item 2 of line i of tCoordinates
end repeat
set the points of graphic "graph" to tCoordinates
set the height of graphic "graph" to 200
set the width of graphic "graph" to 300
set the loc of grc "graph" to the loc of this card
end plotGraphic
</syntaxhighlight>
[https://www.mediafire.com/view/xhi8oq1fawagzbt Result with Vector Graphics]
Displaying the plot with the Line Graph widget
<syntaxhighlight lang="livecode">
on plotLineGraph
local tCoordinates
local x = "0, 1, 2, 3, 4, 5, 6, 7, 8, 9"
local y = "2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0"
if there is a widget "graph" then delete widget "graph"
repeat with i = 1 to the number of items of x
put item i of x into item 1 of line i of tCoordinates
put item i of y into item 2 of line i of tCoordinates
end repeat
create widget "graph" as "com.livecode.widget.linegraph"
set the graphData of widget "graph" to tCoordinates
set the height of widget "graph" to 250
set the width of widget "graph" to 350
set the loc of widget "graph" to the loc of this card
end plotLineGraph
</syntaxhighlight>
[https://www.mediafire.com/view/8wj0l5l5blmd9dg/line_graph.jpg Result with Line Graph Widget]
=={{header|Lua}}==
{{libheader|LÖVE}}
<syntaxhighlight lang="lua">
w_width = love.graphics.getWidth()
w_height = love.graphics.getHeight()
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 = {24,24}
points = {}
x_unit = w_width/x[10]/2
y_unit = w_height/10
--add points to an array properly formatted for the line function
for i=1,10,1 do
table.insert(points, (x[i]*x_unit) + origin[1])
table.insert(points, (w_height-(y[i]*2)) - origin[2])
end
function love.draw()
--draw axes and grid
love.graphics.setColor(0, 0.8, 0)
--draw x axis
love.graphics.line(origin[1], w_height-origin[2], w_width, w_height-origin[2])
--draw y axis
love.graphics.line(origin[1], w_height-origin[2], origin[1], origin[2])
--draw grid
for i=1,20,1 do
love.graphics.line(origin[1], (w_height-origin[2])-(i*y_unit), w_width, (w_height-origin[2])-(i*y_unit))
love.graphics.line(origin[1]+(i*x_unit), origin[2], origin[1]+(i*x_unit), w_height-origin[2])
end
--draw line plot
love.graphics.setColor(0.8, 0, 0)
love.graphics.line(points)
--draw labels
love.graphics.setColor(0.8, 0.8, 0.8)
for i=0,9,1 do
--draw x axis labels
love.graphics.print(i, (x_unit*i) + origin[1], love.graphics.getHeight()-origin[2])
--draw y axis labels
love.graphics.print(i*y_unit/2, origin[1], ((love.graphics.getHeight()-i*y_unit)-origin[2]))
end
end
</syntaxhighlight>
=={{header|M2000 Interpreter}}==
Last statements used for copy the console screen to clipboard
Result image [https://4.bp.blogspot.com/-8XdIVaW79lU/W_iCUBmj92I/AAAAAAAAHbA/TxMl_P22yckQ1Wdi4zsu6k_QVNRZpqJCgCLcBGAs/s1600/graph222.png here]
<syntaxhighlight lang="m2000 interpreter">
Module Pairs {
\\ written in version 9.5 rev. 13
\\ use Gdi+ antialiasing (not work with Wine in Linux, but we get no error)
smooth on
Const center=2, right=3, left=1, blue=1, angle=0, dotline=3
Const size9pt=9, size11pt=11
Cls ,0 ' use current background color, set split screen from line 0
Cursor 0,3
Report center, "Coordinate pairs"
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)
dx=scale.x/2/len(x)
dy=dx 'ratio 1:1
graH=dy*len(x)
Basex=scale.x/4
Basey=(scale.y+graH)/2
Move Basex, Basey
\\ draw use relative coordinates
Draw 0,-graH
\\ Step just move graphic cursor
Step 0, graH
Draw scale.x/2
Step -scale.x/2
\\ scX is 1, not used
max=Y#max()
\\ Auto scale for Y, using 0 for start of axis Y
scY=-graH/((max+5^log(max) ) div 100)/100
\\ make vertical axis using dots with numbers center per dx
j=1
For i=basex+dx to basex+dx*x#max() Step dx
Move i, basey
Step 0, twipsy*10
Legend format$("{0}",array(x,j)), "courier", size9pt, angle, center
Width 1, dotline { draw 0, -graH-twipsy*10,7}
j++
Next i
\\ the same for horizontal axis
HalfTextHeight=Size.y("1","courier", size9pt)/2
For i=basey-dy to basey-dy*x#max() Step dy
Move basex, i
Step -twipsx*10
Width 1, dotline { draw scale.x/2+twipsx*10,,7}
Move basex-100, i+HalfTextHeight
Legend format$("{0}",(i-basey)/scY), "courier", size9pt, angle, left
Next i
ex=each(x) : ey=each(y)
\\ start from first point. We use Draw to for absolute coordinates
Move array(x,0)*dx+Basex, array(y,0)*scy+Basey
While ex, ey {
Width 2 {
Draw to array(ex)*dx+Basex, array(ey)*scy+Basey, blue
}
}
\\ second pass for marks and labels
ex=each(x) : ey=each(y)
While ex, ey {
Move array(ex)*dx+Basex, array(ey)*scy+Basey
Step -75, -75
Pen 12 {draw 150: draw 0,150 : draw -150 : draw 0,-150}
Pen 13 {
Step 200, -200
Legend format$("({0}-{1})",array(ex),array(ey) ), "courier bold", size11pt, angle, right
}
}
\\ screenshot to clipboard
Screenshot$=""
Move 0,0
Copy scale.x, scale.y to Screenshot$
Clipboard Screenshot$
a$=key$
}
Pairs
</syntaxhighlight>
=={{header|Maple}}==
<syntaxhighlight lang="maple">x := Vector([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]):
y := Vector([2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0]):
plot(x,y,style="point");</syntaxhighlight>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">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};
ListPlot[{x, y} // Transpose]</
{{out}}
[http://i43.tinypic.com/2a689yw.png]
=={{header|MATLAB}}==
<
>> y = [2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0];
>> plot(x,y,'.-')</
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
".." (m, n) := makelist (i, i, m, n); infix ("..")$
x: 0 .. 9$
y:[2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0]$
wxplot2d(['discrete, x, y], [style, [points,5,1,1]], [gnuplot_term, png], [gnuplot_out_file, "qsort-range-10-9.png"])$
</syntaxhighlight>
[http://img28.picoodle.com/img/img28/4/2/7/f_qsortrange1m_1b7f493.png qsort-range-10-9.png]
=={{header|Nim}}==
===Using gnuplot===
{{libheader|gnuplotlib.nim}}
There exists two libraries providing a Nim interface to “gnuplot” (the GNU plotting program), which are named “gnuplot” and “gnuplotlib”. We have chosen the second one as it is be more complete and more convenient to use.
The library launches “gnuplot” which does the plotting. From “gnuplot”, it is possible to save the drawing into a PDF, a SVG or an image (BMP, PNG) file.
<syntaxhighlight lang="nim">import gnuplot
let
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]
withGnuPlot:
plot(x, y, "Coordinate pairs")
</syntaxhighlight>
===Using ggplotnim===
{{libheader|ggplotnim}}
This library doesn’t use an external process to does the plotting. It uses a syntax mostly compliant with “ggplot2” syntax.
<syntaxhighlight lang="nim">import ggplotnim
let
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]
let df = seqsToDf(x, y) # Build a dataframe.
df.ggplot(aes("x", "y")) +
ggtitle("Coordinate pairs") +
geomLine() +
themeOpaque() +
ggsave("coordinate_pairs.png")</syntaxhighlight>
=={{header|OCaml}}==
<
open Graphics
Line 1,290 ⟶ 2,248:
ignore(wait_next_event [Key_pressed]);
close_graph();
;;</
Using the [http://forge.ocamlcore.org/projects/archimedes/ Archimedes] library,
one can write:
[[Image:Archimedes.png|300px|thumb|right|Archimedes plot (graphics output).]]
<
module A = Archimedes
Line 1,306 ⟶ 2,264:
A.Array.y vp y;
A.close vp
</syntaxhighlight>
=={{header|Octave}}==
<
y = [2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0];
plot(x,y,"o");
pause;</
=={{header|Ol}}==
<syntaxhighlight lang="scheme">
; define input arrays
(define x '(0 1 2 3 4 5 6 7 8 9))
(define y '(2.7 2.8 31.4 38.1 58.0 76.2 100.5 130.0 149.3 180.0))
; render
(import (lib gl2))
(glOrtho 0 10 0 200 0 1)
(gl:set-renderer (lambda (mouse)
(glClear GL_COLOR_BUFFER_BIT)
(glColor3f 0 1 0)
(glBegin GL_LINE_STRIP)
(map glVertex2f x y)
(glEnd)))
</syntaxhighlight>
=={{header|PARI/GP}}==
<syntaxhighlight lang
=={{header|Perl}}==
===GD::Graph library===
{{libheader|GD::Graph}}
<
@data = (
Line 1,325 ⟶ 2,304:
[2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0],
);
$graph = GD::Graph::points->new(400, 300);
open my $fh, '>', "qsort-range-10-9.png";
binmode $fh;
print $fh $graph->plot(\@data)->png;
close $fh;</syntaxhighlight>
===Imager::Plot library===
{{libheader|Imager::Plot}}
<
use Imager::Plot;
Line 1,364 ⟶ 2,340:
$img->box(filled => 1, color => 'white');
$plot->Render(Image => $img, Xoff => 50, Yoff => 350);
$img->write(file => 'qsort-range-10-9.png');</
=={{header|
<syntaxhighlight lang="java">
//Aamrun, 26th June 2022
size(300,300);
surface.setTitle("Rosetta Plot");
stroke(#ff0000);
for(int i=0;i<x.length;i++){
ellipse(x[i],y[i],3,3);
}
</syntaxhighlight>
=={{header|Phix}}==
{{libheader|Phix/pGUI}}
Output same as BBC BASIC, you can run this online [http://phix.x10.mx/p2js/Plot_coordinate_pairs.htm here].
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Plot_coordinate_pairs.exw
-- ======================================
--</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">IupGraph</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">x</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">},</span>
<span style="color: #000000;">y</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">2.7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2.8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">31.4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">38.1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">58.0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">76.2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">100.5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">130.0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">149.3</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">180.0</span><span style="color: #0000FF;">}</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">get_data</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000000;">graph</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #0000FF;">{{</span><span style="color: #000000;">x</span><span style="color: #0000FF;">,</span><span style="color: #000000;">y</span><span style="color: #0000FF;">,</span><span style="color: #004600;">CD_BLUE</span><span style="color: #0000FF;">}}</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #7060A8;">IupOpen</span><span style="color: #0000FF;">()</span>
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">graph</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">IupGraph</span><span style="color: #0000FF;">(</span><span style="color: #000000;">get_data</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">dlg</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupDialog</span><span style="color: #0000FF;">(</span><span style="color: #000000;">graph</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`TITLE="Plot coordinate pairs"`</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetAttributes</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"RASTERSIZE=320x240,MINSIZE=320x200"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetAttributes</span><span style="color: #0000FF;">(</span><span style="color: #000000;">graph</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"XTICK=1,XMIN=0,XMAX=9"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetAttributes</span><span style="color: #0000FF;">(</span><span style="color: #000000;">graph</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"YTICK=20,YMIN=0,YMAX=180"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupShow</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">IupMainLoop</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</syntaxhighlight>-->
=={{header|PicoLisp}}==
[[Image: Plotxy-picoLisp.png|thumb|right|200px|Example picoLisp output]]
<
(scl 1)
Line 1,422 ⟶ 2,426:
(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")</
=={{header|PostScript}}==
<syntaxhighlight lang="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
Line 1,436 ⟶ 2,441:
}repeat
stroke
</syntaxhighlight>
=={{header|PureBasic}}==
<
x.i
y.f
Line 1,529 ⟶ 2,534:
serie_y:
Data.f 2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0
EndDataSection</
[[File:PureBasic PlotData.png]]
Line 1,539 ⟶ 2,544:
Interactive session:
<
>>> y = [2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0]
Line 1,545 ⟶ 2,550:
>>> pylab.plot(x, y, 'bo')
>>> pylab.savefig('qsort-range-10-9.png')
</syntaxhighlight>
See some other examples:
* [http://matplotlib.org/examples/pylab_examples/simple_plot.html simple plot]
Line 1,552 ⟶ 2,557:
==={{libheader|VPython}}===
<
from visual import *
from visual.graph import *
Line 1,581 ⟶ 2,586:
label(display=plot1.display, text="Look here",
pos=(6,100.5), xoffset=30,yoffset=-20 )
</syntaxhighlight>
=={{header|R}}==
R has several different plotting paradigms. First we define the data.
<
y <- c(2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0)</
===Base graphics===
<syntaxhighlight lang
===Lattice/grid graphics===
{{libheader|lattice}}
<
xyplot(y~x)</
===Grammar of graphics===
{{libheader|ggplot2}}
<
qplot(x,y)</
=={{header|Racket}}==
Racket has a built-in plotting library
<
(require plot)
Line 1,607 ⟶ 2,612:
(plot-new-window? #t)
(plot (points (map vector x y)))</
This opens a new window with this image (with interactive zooming)
Line 1,613 ⟶ 2,618:
And this
<
(require plot)
Line 1,620 ⟶ 2,625:
(plot-new-window? #t)
(plot (
opens a new window with this image
[[File:LinesRacket.png]]
=={{header|
(formerly Perl 6)
{{works with|Rakudo|2018.03}}
Generate an SVG image file.
<syntaxhighlight lang="raku" line>use SVG;
use SVG::Plot;
my @x = 0..9;
my @y = (2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0);
say SVG.serialize: SVG::Plot.new(
width => 512,
height => 512,
x => @x,
x-tick-step => { 1 },
min-y-axis => 0,
values => [@y,],
title => 'Coordinate Pairs',
).plot(:lines);</syntaxhighlight>
[[File:Coordinate-pairs-perl6.svg]]
=={{header|REXX}}==
See [[Plot coordinate pairs/REXX]] for the '''$PLOT''' program.
===without point labels===
Example usage:
<
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
$=
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*/ /*$≡
call '$PLOT' $ /*invoke the REXX program: $PLOT
exit rc /*stick a fork in it, we're all done. */</
{{out
<pre>
│180 ∙
Line 1,688 ⟶ 2,714:
└──────────────────────────────────────────────────────────────────────────────
</pre>
===with point labels===
<syntaxhighlight lang="rexx">/*REXX program plots X,Y coördinate pairs of numbers with plain (ASCII) characters.*/
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
$=
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. */</syntaxhighlight>
{{out|output|text= when using the default input:}}
<pre>
│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)
└──────────────────────────────────────────────────────────────────────────────────────────────
</pre>
=={{header|Ring}}==
<syntaxhighlight lang="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
</syntaxhighlight>
Output:
https://www.dropbox.com/s/q6tra0cqoty4pya/Plot.jpg?dl=0
=={{header|RPL}}==
{{works with|HP|48G}}
[[File:PlotPairs.png|thumb|alt=HP-48G emulator screenshot|HP-48G emulator screenshot]]
≪ → x y
≪ ERASE <span style="color:grey">@ clear graphics display</span>
x 0 + ≪ MIN ≫ STREAM x ≪ MAX ≫ STREAM XRNG <span style="color:grey">@ set x range</span>
y 0 + ≪ MIN ≫ STREAM y ≪ MAX ≫ STREAM YRNG <span style="color:grey">@ set y range</span>
1 x SIZE '''FOR''' j
x j GET y j GET R→C <span style="color:grey">@ generate coordinates pair </span>
'''IF''' j 1 > '''THEN''' SWAP OVER LINE '''END''' <span style="color:grey">@ draw a line from previous pair</span>
'''NEXT''' DROP
{ (0,0) 10 "x" "y" } AXES DRAX LABEL <span style="color:grey">@ draw axes and labels </span>
{ } PVIEW <span style="color:grey">@ display graphics </span>
≫ ≫ '<span style="color:blue">PLOTXY</span>' STO
{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}
<span style="color:blue">PLOTXY</span>
=={{header|Ruby}}==
Line 1,694 ⟶ 2,894:
[[File:Ruby.plotxy.png|300px|thumb|right|gnuplot of x,y arrays]]
<
x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Line 1,705 ⟶ 2,905:
end
end
end</
=={{header|Scala}}==
{{libheader|Scala}}
<
import scala.swing.{ MainFrame, Panel, Rectangle }
import java.awt.{ Color, Graphics2D, geom }
Line 1,814 ⟶ 3,014:
contents = ui
}
}</
=={{header|Scilab}}==
<syntaxhighlight lang="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)</syntaxhighlight>
=={{header|Sidef}}==
{{trans|Perl}}
<
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 =
=={{header|Stata}}==
<syntaxhighlight lang="stata">clear
input x y
0 2.7
1 2.8
2 31.4
3 38.1
4 58.0
5 76.2
6 100.5
7 130.0
8 149.3
9 180.0
end
lines y x
graph export image.png</syntaxhighlight>
=={{header|Tcl}}==
{{libheader|Tk}}
{{libheader|Img}}
[[File:Tcl_Plotxy.png|thumb|right|150px|Screenshot for Tcl code]]
This solution does not use existing plotting packages, but constructs the graphics from bare-metal Tk code.
<
# The actual plotting engine
Line 1,891 ⟶ 3,114:
package require Img
set 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.
Line 1,899 ⟶ 3,122:
[[File:Plotxy-TI-89.png|thumb|right|200px|TI-89 screenshot]]
<
PlotsOff
NewPlot 1, 1, x, y
ZoomData</
=={{header|Ursala}}==
Line 1,910 ⟶ 3,133:
Here's the way to do it just as a quick check (all default settings
and dots connected with straight lines).
<
#import flo
#import fit
Line 1,920 ⟶ 3,143:
#output dot'tex' latex_document+ plot
main = visualization[curves: <curve[points: ~&p/x y]>]</
([http://i25.tinypic.com/33oi74j.jpg output])
Line 1,928 ⟶ 3,151:
labeled.
<
visualization[
Line 1,944 ⟶ 3,167:
scattered: true,
points: ~&p/x y,
attributes: {'linecolor': 'black'}]>]</
([http://i32.tinypic.com/x1x6cz.jpg output])
=={{header|VBA}}==
Using Excel
<syntaxhighlight lang="vb">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 With
End Sub
Public 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, y
End Sub</syntaxhighlight>
=={{header|Wren}}==
{{libheader|DOME}}
<syntaxhighlight lang="wren">import "graphics" for Canvas, ImageData, Color
import "dome" for Window
import "math" for Point
class PlotCoordinates {
construct new(width, height) {
Window.title = "Plot coordinates"
Window.resize(width, height)
Canvas.resize(width, height)
_width = width
_height = height
}
init() {
var x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
var y = [2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0]
plotCoordinates(x, y)
}
plotCoordinates(x, y) {
var n = x.count
// draw axes
Canvas.line(40, _height - 40, _width - 40, _height - 40, Color.blue, 2)
Canvas.line(40, _height - 40, 40, 40, Color.blue, 2)
var length = 40 * n
var div = length / 10
var j = 0
for (i in 0..9) {
var p = Point.new(40 + j, _height - 40)
Canvas.print(i.toString, p.x - 4, p.y + 4, Color.white)
j = j + div
}
j = div
for (i in 1..9) {
var p = Point.new(10, _height - 40 - j)
var s = (i * 20).toString
if (s.count == 2) s = " " + s
Canvas.print(s, p.x, p.y, Color.white)
j = j + div
}
Canvas.print("X", _width - 44, _height - 36, Color.green)
Canvas.print("Y", 20, 40, Color.green)
// plot points
var xStart = 40
var xScale = 40
var yStart = 40
var yScale = 2
var points = List.filled(n, null)
for (i in 0...n) {
points[i] = Point.new(xStart + x[i]*xScale, _height - yStart - y[i]*yScale)
}
Canvas.circlefill(points[0].x, points[0].y, 3, Color.red)
for (i in 1...n) {
Canvas.line(points[i-1].x, points[i-1].y, points[i].x, points[i].y, Color.red)
Canvas.circlefill(points[i].x, points[i].y, 3, Color.red)
}
}
update() {}
draw(alpha) {}
}
var Game = PlotCoordinates.new(500, 500)</syntaxhighlight>
=={{header|XPL0}}==
Line 1,954 ⟶ 3,268:
[[File:PlotXPL0.png|140px|thumb|right|Output]]
<
def ScrW=640, ScrH=480, VidMode=$101;
Line 1,987 ⟶ 3,301:
if ChIn(1) then []; \wait for key
SetVid(3); \restore text
]</
=={{header|Yorick}}==
<
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;</
<gallery>
File:Plotxy-yorick-plmk.png|Output with plmk
Line 2,006 ⟶ 3,320:
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 # X11
Line 2,028 ⟶ 3,342:
gnuplot:=System.popen("gnuplot","w");
gnuplot.write(cmd); gnuplot.flush();
ask("Hit return to finish"); gnuplot.close();</
|