Plot coordinate pairs: Difference between revisions
m
→{{header|EasyLang}}
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: use PNG format for both libraries) |
|||
(12 intermediate revisions by 8 users not shown) | |||
Line 13:
=={{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 */
Line 295:
.include "../includeARM64.inc"
</syntaxhighlight>
{{Output}}
<pre>
Line 326:
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
<
DEFINE PTR="CARD"
Line 517:
DO UNTIL CH#$FF OD
CH=$FF
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Plot_coordinate_pairs.png Screenshot from Atari 8-bit computer]
Line 526:
{{libheader|GtkAda}}
[[Image:Gtkada_plot.png|thumb|right|100px|Example GtkAda plot]]
<
with Gtk.Main;
with Gtk.Window; use Gtk.Window;
Line 573:
Gtk.Main.Main;
end PlotCoords;
</syntaxhighlight>
=={{header|ALGOL 68}}==
Line 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 616:
);
PR READ "postlude/exception.a68" PR</
=={{header|AutoHotkey}}==
Line 622:
{{works with|AutoHotkey_L}}(AutoHotkey1.1+)
{{libheader|GDIP}}
<
#NoEnv
SetBatchLines, -1
Line 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 723:
DRAW 100*x(i%),4*y(i%)
ENDIF
NEXT</
=={{header|C}}==
Line 730:
{{libheader|libplot}}
<
#include <stdlib.h>
#include <math.h>
Line 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 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 982:
plot(x, y, N, "r-o");
return 0;
}</
=={{header|C++}}==
[[File:plot_cpp.png|300px]]
<
#include <windows.h>
#include <string>
Line 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}}
Line 1,227:
{{Trans|Go}}
Boost.Process is part of [https://github.com/MaiconSoft/DelphiBoostLib DelphiBoostLib].
<syntaxhighlight lang="delphi">
program Plot_coordinate_pairs;
Line 1,255:
plot.Free;
readln;
end.</
=={{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
line 10
line 95
textsize 3
n = len x[]
m = 0
for i
m = y[i]
.
.
linewidth 0.1
sty = m div 9
for i
move
move
.
stx = x[n
for i
move i * 9 + 10
move i * 9 + 10
.
color 900
linewidth 0.5
for i
x = x[i] * 9 / stx + 10
y =
.
</syntaxhighlight>
=={{header|EchoLisp}}==
Resulting image [http://www.echolalie.org/echolisp/images/plot-coordinates.png here].
<
(lib 'plot)
Line 1,312 ⟶ 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 1,330 ⟶ 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 1,337 ⟶ 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 1,344 ⟶ 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}}
<
ui.gadgets ui.gadgets.charts ui.gadgets.charts.lines ;
Line 1,354 ⟶ 1,355:
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</
=={{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===
<
For i = 0 To 9
x(i) = i
Line 1,396 ⟶ 1,399:
Locate (21 - (y(i)/ 10)), (x(i) * 4) + 2 : Print "."
Next i
Sleep</
=={{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 1,414 ⟶ 1,417:
8 149.3
9 180.0
e</
<br clear=right>
Line 1,423 ⟶ 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 1,452 ⟶ 1,455:
w.Close()
g.Wait()
}</
===gonum/plot===
{{libheader|gonum/plot}}
[[File:GoPoints.png|right|Go plot]]
<
import (
Line 1,487 ⟶ 1,490:
log.Fatal(err)
}
}</
=={{header|Groovy}}==
Line 1,493 ⟶ 1,496:
[[File:GroovyPlotDemo.png|300px|thumb|right|Screenshot of groovy solution]]
<
import javax.swing.JFrame
import org.jfree.chart.ChartFactory
Line 1,520 ⟶ 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 1,539 ⟶ 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 1,629 ⟶ 1,632:
every q[i := 1 to *q] := pix - q[i]
return P
end</
{{libheader|Icon Programming Library}}
Line 1,637 ⟶ 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,648 ⟶ 1,651:
=={{header|Java}}==
<
import java.awt.event.*;
import java.awt.geom.*;
Line 1,737 ⟶ 1,740:
}
}
</syntaxhighlight>
=={{header|jq}}==
Line 1,744 ⟶ 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,767 ⟶ 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,776 ⟶ 1,779:
main="Scatterplot Example",
xlab="x-axis label", # x-axis label
ylab="y-axis label" ) # y-axis label</
=={{header|Julia}}==
Using Plots library with PlotlyJS as backend:
<
plotlyjs()
Line 1,788 ⟶ 1,791:
p = scatter(x, y)
savefig(p, "/tmp/testplot.png")</
=={{header|Kotlin}}==
{{libheader|JFreeChart}}
{{trans|Groovy}}
<
import org.jfree.chart.ChartFactory
Line 1,831 ⟶ 1,834:
}
}
}</
{{out}}
Line 1,839 ⟶ 1,842:
=={{header|Lambdatalk}}==
<
1) define X & Y:
Line 1,876 ⟶ 1,879:
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,915 ⟶ 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,981 ⟶ 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
Line 2,009 ⟶ 2,012:
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
Line 2,029 ⟶ 2,032:
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]
Line 2,035 ⟶ 2,038:
{{libheader|LÖVE}}
<
w_width = love.graphics.getWidth()
w_height = love.graphics.getHeight()
Line 2,081 ⟶ 2,084:
end
</syntaxhighlight>
=={{header|M2000 Interpreter}}==
Line 2,088 ⟶ 2,091:
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
Line 2,161 ⟶ 2,164:
}
Pairs
</syntaxhighlight>
=={{header|Maple}}==
<
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");</
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
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]
Line 2,190 ⟶ 2,196:
=={{header|Nim}}==
===Using gnuplot===
{{libheader|
There exists two libraries providing a Nim interface to “gnuplot” (the GNU plotting program), which are named “gnuplot” and “gnuplotlib”. We have chosen the
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.
<
let
Line 2,201 ⟶ 2,207:
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.
<
let
Line 2,219 ⟶ 2,226:
geomLine() +
themeOpaque() +
ggsave("coordinate_pairs.png")</
=={{header|OCaml}}==
<
open Graphics
Line 2,241 ⟶ 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 2,257 ⟶ 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}}==
<
; define input arrays
(define x '(0 1 2 3 4 5 6 7 8 9))
Line 2,281 ⟶ 2,288:
(map glVertex2f x y)
(glEnd)))
</syntaxhighlight>
=={{header|PARI/GP}}==
<syntaxhighlight lang
=={{header|Perl}}==
Line 2,291 ⟶ 2,298:
{{libheader|GD::Graph}}
<
@data = (
Line 2,302 ⟶ 2,309:
binmode $fh;
print $fh $graph->plot(\@data)->png;
close $fh;</
===Imager::Plot library===
{{libheader|Imager::Plot}}
<
use Imager::Plot;
Line 2,333 ⟶ 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|Processing}}==
<syntaxhighlight lang="java">
//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);
}
</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].
<!--<
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Plot_coordinate_pairs.exw
Line 2,363 ⟶ 2,388:
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</
=={{header|PicoLisp}}==
[[Image: Plotxy-picoLisp.png|thumb|right|200px|Example picoLisp output]]
<
(scl 1)
Line 2,401 ⟶ 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 2,416 ⟶ 2,441:
}repeat
stroke
</syntaxhighlight>
=={{header|PureBasic}}==
<
x.i
y.f
Line 2,509 ⟶ 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 2,519 ⟶ 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 2,525 ⟶ 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 2,532 ⟶ 2,557:
==={{libheader|VPython}}===
<
from visual import *
from visual.graph import *
Line 2,561 ⟶ 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 2,587 ⟶ 2,612:
(plot-new-window? #t)
(plot (points (map vector x y)))</
This opens a new window with this image (with interactive zooming)
Line 2,593 ⟶ 2,618:
And this
<
(require plot)
Line 2,600 ⟶ 2,625:
(plot-new-window? #t)
(plot (lines (map vector x y)))</
opens a new window with this image
Line 2,609 ⟶ 2,634:
{{works with|Rakudo|2018.03}}
Generate an SVG image file.
<syntaxhighlight lang="raku"
use SVG::Plot;
Line 2,623 ⟶ 2,648:
values => [@y,],
title => 'Coordinate Pairs',
).plot(:lines);</
[[File:Coordinate-pairs-perl6.svg]]
Line 2,630 ⟶ 2,655:
===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
Line 2,638 ⟶ 2,663:
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. */</
{{out|output|text= when using the default input:}}
<pre>
Line 2,691 ⟶ 2,716:
===with point labels===
<
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 2,699 ⟶ 2,724:
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. */</
{{out|output|text= when using the default input:}}
<pre>
Line 2,764 ⟶ 2,789:
=={{header|Ring}}==
<
# Project : Plot coordinate pairs
Line 2,840 ⟶ 2,865:
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 2,850 ⟶ 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 2,861 ⟶ 2,905:
end
end
end</
=={{header|Scala}}==
{{libheader|Scala}}
<
import scala.swing.{ MainFrame, Panel, Rectangle }
import java.awt.{ Color, Graphics2D, geom }
Line 2,970 ⟶ 3,014:
contents = ui
}
}</
=={{header|Scilab}}==
<
--> y = [2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0];
--> plot2d(x,y)</
=={{header|Sidef}}==
{{trans|Perl}}
<
var data = [
Line 2,990 ⟶ 3,034:
var format = 'png'
File("qsort-range.#{format}").write(gd.(format), :raw)</
=={{header|Stata}}==
<
input x y
0 2.7
Line 3,008 ⟶ 3,052:
lines y x
graph export image.png</
=={{header|Tcl}}==
Line 3,015 ⟶ 3,059:
[[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 3,070 ⟶ 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 3,078 ⟶ 3,122:
[[File:Plotxy-TI-89.png|thumb|right|200px|TI-89 screenshot]]
<
PlotsOff
NewPlot 1, 1, x, y
ZoomData</
=={{header|Ursala}}==
Line 3,089 ⟶ 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 3,099 ⟶ 3,143:
#output dot'tex' latex_document+ plot
main = visualization[curves: <curve[points: ~&p/x y]>]</
([http://i25.tinypic.com/33oi74j.jpg output])
Line 3,107 ⟶ 3,151:
labeled.
<
visualization[
Line 3,123 ⟶ 3,167:
scattered: true,
points: ~&p/x y,
attributes: {'linecolor': 'black'}]>]</
([http://i32.tinypic.com/x1x6cz.jpg output])
=={{header|VBA}}==
Using Excel
<
Dim chrt As Chart
Set chrt = ActiveSheet.Shapes.AddChart.Chart
Line 3,147 ⟶ 3,191:
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</
=={{header|Wren}}==
{{libheader|DOME}}
<
import "dome" for Window
import "math" for Point
Line 3,215 ⟶ 3,259:
}
var Game = PlotCoordinates.new(500, 500)</
=={{header|XPL0}}==
Line 3,224 ⟶ 3,268:
[[File:PlotXPL0.png|140px|thumb|right|Output]]
<
def ScrW=640, ScrH=480, VidMode=$101;
Line 3,257 ⟶ 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 3,276 ⟶ 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 3,298 ⟶ 3,342:
gnuplot:=System.popen("gnuplot","w");
gnuplot.write(cmd); gnuplot.flush();
ask("Hit return to finish"); gnuplot.close();</
|