easyplot-1.0: A tiny plotting library, utilizes gnuplot for plotting.

Safe HaskellSafe-Inferred

Graphics.EasyPlot

Contents

Description

A simple wrapper to the gnuplot command line utility.

Typically you will invoke a plot like so:

 plot X11 $ Data2D [Title "Sample Data"] [] [(1, 2), (2, 4), ...]

To plot a function, use the following:

 plot X11 $ Function2D [Title "Sine and Cosine"] [] (\x -> sin x * cos x)

There is also a shortcut available - the following plots the sine function:

 plot X11 sin

Output can go into a file, too (See TerminalType):

 plot (PNG "plot.png") (sin . cos)

Haskell functions are plotted via a set of tuples obtained form the function. If you want to make use of gnuplots mighty function plotting functions you can pass a Gnuplot2D or Gnuplot3D object to plot.

 plot X11 $ Gnuplot2D [Color Blue] [] "2**cos(x)"

For 3D-Plots there is a shortcut available by directly passing a String:

 plot X11 "x*y"

Multiple graphs can be shown simply by passing a list of these:

 plot X11 [ Data2D [Title "Graph 1", Color Red] [] [(x, x ** 3) | x <- [-4,-3.9..4]]
          , Function2D [Title "Function 2", Color Blue] [] (\x -> negate $ x ** 2) ]

For 3D Graphs it is useful to be able to interact with the graph (See plot' and GnuplotOption):

 plot' [Interactive] X11 $ Gnuplot3D [Color Magenta] [] "x ** 2 + y ** 3"

If you want to know the command that SimplePlot uses to plot your graph, turn on debugging:

 plot' [Debug] X11 $ Gnuplot3D [Color Magenta] [] "x ** 4 + y ** 3"
 > set term x11 persist; splot x ** 4 + y ** 3 lc rgb "magenta"

Synopsis

Plotting

class Plot a whereSource

Provides the plot function for different kinds of graphs (2D and 3D)

Methods

plotSource

Arguments

:: TerminalType

The terminal to be used for output.

-> a

The graph to plot. A Graph2D or Graph3D or a list of these.

-> IO Bool

Whether the plot was successfull or not.

Do a plot to the terminal (i.e. a window will open and your plot can be seen)

plot' :: [GnuplotOption] -> TerminalType -> a -> IO BoolSource

Instances

Plot String

plot accepts a custom string which is then to be interpreted by gnu plot. The function will be interpreted as Gnuplot3D.

(Fractional x, Enum x, Show x, Fractional y, Enum y, Show y, Num z, Show z) => Plot [x -> y -> z]

A list of 3D functions can be plotted directly using plot

(Fractional x, Enum x, Show x, Num y, Show y) => Plot [x -> y]

A list of 2D functions can be plotted directly using plot

Plot [String]

plots mutliple 3D functions using gnuplots native function parser and renderer. The String will be interpreted as Gnuplot3D.

(Fractional x, Enum x, Num x, Show x, Num y, Show y) => Plot [(x, y)]

A list of tuples can be plotted directly using plot

(Fractional x, Enum x, Show x, Fractional y, Enum y, Show y, Num z, Show z) => Plot [(x, y, z)]

A list of triples can be plotted directly using plot

(Fractional x, Enum x, Show x, Fractional y, Enum y, Show y, Num z, Show z) => Plot [Graph3D x y z]

plot can be used to plot a list of Graph3D

(Fractional x, Enum x, Show x, Num y, Show y) => Plot [Graph2D x y]

plot can be used to plot a list of Graph2D.

(Fractional x, Enum x, Show x, Fractional y, Enum y, Show y, Num z, Show z) => Plot (x -> y -> z)

A 3D function can be plotted directly using plot

(Fractional x, Enum x, Show x, Num y, Show y) => Plot (x -> y)

A 2D function can be plotted directly using plot

(Fractional x, Enum x, Show x, Num y, Show y) => Plot (Graph2D x y)

plot can be used to plot a single Graph2D.

(Fractional x, Enum x, Show x, Fractional y, Enum y, Show y, Num z, Show z) => Plot (Graph3D x y z)

plot can be used to plot a single Graph3D.

Graphs for 2D and 3D plots

data Graph2D x y Source

A two dimensional set of data to plot.

Constructors

Function2D [Option] [Option2D x y] (x -> y)

plots a Haskell function x -> y

Data2D [Option] [Option2D x y] [(x, y)]

plots a set of tuples.

Gnuplot2D [Option] [Option2D x y] String

plots a custom function passed to Gnuplot (like x**2 + 10)

Instances

(Fractional x, Enum x, Show x, Num y, Show y) => Plot [Graph2D x y]

plot can be used to plot a list of Graph2D.

(Fractional x, Enum x, Show x, Num y, Show y) => Plot (Graph2D x y)

plot can be used to plot a single Graph2D.

data Graph3D x y z Source

A three dimensional set of data to plot.

Constructors

Function3D [Option] [Option3D x y z] (x -> y -> z)

plots a Haskell function x -> y -> z

Data3D [Option] [Option3D x y z] [(x, y, z)]

plots a set of triples.

Gnuplot3D [Option] [Option3D x y z] String

plots a custom function passed to Gnuplot (like x*y)

Instances

(Fractional x, Enum x, Show x, Fractional y, Enum y, Show y, Num z, Show z) => Plot [Graph3D x y z]

plot can be used to plot a list of Graph3D

(Fractional x, Enum x, Show x, Fractional y, Enum y, Show y, Num z, Show z) => Plot (Graph3D x y z)

plot can be used to plot a single Graph3D.

Configuration and other options

data TerminalType Source

TerminalType determines where the output of gnuplot should go.

Constructors

Aqua

Output on Mac OS X (Aqua Terminal).

Windows

Output for MS Windows.

X11

Output to the X Window System.

PS FilePath

Output into a Postscript file.

EPS FilePath

Output into an EPS file.

PNG FilePath

Output as Portable Network Graphic into file.

PDF FilePath

Output as Portable Document Format into a file.

SVG FilePath

Output as Scalable Vector Graphic into a file.

GIF FilePath

Output as Graphics Interchange Format into a file.

JPEG FilePath

Output into a JPEG file.

Latex FilePath

Output as LaTeX.

data Style Source

The Style of a graph.

Constructors

Lines

points in the plot are interconnected by lines.

Points

data points are little cross symbols.

Dots

data points are real dots (approx the size of a pixel).

Impulses 
Linespoints 

data Option Source

Options on how to render a graph.

Constructors

Style Style

The style for a graph.

Title String

The title for a graph in a plot (or a filename like plot1.dat).

Color Color

The line-color for the graph (or if it consist of Dots or Points the color of these)

data Option2D x y Source

Options which are exclusively available for 2D plots.

Constructors

Range x x

Plots the function for the specified x range

For [x]

Plots the function only for the given x values

Step x

Uses the given step-size for plotting along the x-axis

data Option3D x y z Source

Options which are exclusively available for 3D plots.

Constructors

RangeX x x

Plots the function for the specified x range

RangeY y y

Plots the function for the specified y range

ForX [x]

Plots the function only for the given x values

ForY [y]

Plots the function only for the given y values

StepX x

Uses the given step-size for plotting along the x-axis

StepY y

Uses the given step-size for plotting along the y-axis

data GnuplotOption Source

Options which can be used with plot'

Constructors

Interactive

keeps gnuplot open, so that you can interact with the plot (only usefull with X11)

Debug

prints the command used for running gnuplot.

Instances