textPlot-0.4: Plot functions in text.

Safe HaskellNone
LanguageHaskell98

TextPlot

Contents

Synopsis

Data types

type Function = Double -> Double Source

A function of one variable (x -> y).

type Range = (Double, Double) Source

Range of values (from, to).

class Plot a Source

Any kind of of plot.

Minimal complete definition

draw

class Plot plot => EditPlot plot function | plot -> function where Source

A type class with functional dependency to allow the same editing operations across all plot types.

Methods

thenPlot Source

Arguments

:: plot 
-> function 
-> plot

add another function to the plot

xlim Source

Arguments

:: plot 
-> Range 
-> plot

set limits of the abscissa (x) axis

ylim Source

Arguments

:: plot 
-> Range 
-> plot

set limits of the ordinate (y) axis

(.+) :: EditPlot p f => p -> f -> p Source

Shortcut to thenPlot. Mnemonics: plus to add another function.

(.-) :: EditPlot p f => p -> Range -> p Source

Shortcut to xlim. Mnemonics: horizontal bar followed by horizontal range.

(.|) :: EditPlot p f => p -> Range -> p Source

Shortcut to ylim. Mnemonics: vertical bar followed by vertical range.

Plot types

data XYPlot Source

Plot one or more functions (x -> y) in Cartesian coordinates.

Constructors

XYPlot 

Fields

fp'xlim :: Range

limits of the abscissa (x) axis

fp'ylim :: Range

limits of the ordinate (y) axis

fp'functions :: [Function]

functions to plot

emptyXYPlot :: XYPlot Source

A default empty XYPlot with bounds of a unit square.

data ParamXYPlot Source

Plot one or more parametric functions in Cartesian coordiantes.

Constructors

ParamXYPlot 

Fields

param'xlim :: Range

limits of the abscissa (x) axis

param'ylim :: Range

limits of the ordinate (y) axis

param'functions :: [ParamFunction]

functions to plot

data ParamFunction Source

Constructors

ParamFunction 

Fields

xfun :: Function

the first parametrized variable (t -> x)

yfun :: Function

the second parametrized variable (t -> y)

tlim :: Range

range of the free parameter t

data PolarPlot Source

Plot one or more functions in polar coordinates.

Constructors

PolarPlot 

Fields

polar'xlim :: Range

limits of the abscissa (x) axis

polar'ylim :: Range

limits of the ordinate (y) axis

polar'functions :: [PolarFunction]

functions to plot

data PolarFunction Source

Constructors

PolarFunction 

Fields

rfun :: Function

radius as a function of angle phi (phi -> r)

philim :: (Double, Double)

range of the angle argument phi

Screen representation

data PlotConfig Source

Constructors

PlotConfig 

Fields

c'width :: Int

plot width in characters

c'height :: Int

plot height in characters

c'samples :: Int

samples per line

c'showAxes :: Bool

draw axes or not

defaultConfig :: PlotConfig Source

Default plot dimensions, suitable for 80x24 terminals.

Output

plot :: Plot p => p -> String Source

Convert a plot to a multiline String with default configuration

plotWithConfig :: Plot p => PlotConfig -> p -> String Source

Convert a plot to multiline String with custom configuration

printPlot :: Plot p => p -> IO () Source

Print a plot with default configuration

Example

Plot a mexican hat wavelet function:

ghci> let hat t = 0.5*(1-t**2)*exp(-0.5*t**2)/(sqrt (3*(sqrt pi)))
ghci> let plot = emptyXYPlot .+ hat .- (-5,5) .| (-0.125,0.25)
ghci> printPlot plot
       ^
  0.25 +
       |
       |                             ooo
       |                            o   o
       |
       |                           o     o
       |
       |
       |                          o       o
       |
       |                         o         o
       |
       |
       |oooooooooooo            o           o            ooooooooooo
       |            oo                                 oo
       |              oo       o             o       oo
       |                o     o               o     o
       |                 ooo o                 o ooo
       |                    o                   o
-0.125 +
        +-----------------------------------------------------------+->
        -5.0                                                      5.0

A parametric plot:

ghci> let circle = ParamFunction sin cos (0,2*pi)
ghci> let paramplot = emptyParamXYPlot `thenPlot` circle `xlim` (-1.1,1.1) `ylim` (-1.1,1.1)
ghci> printPlot paramplot
     ^
 1.1 +
     |                    ooooooooooooooooooooo
     |              ooooooo                   ooooooo
     |           oooo                               oooo
     |        ooo                                       ooo
     |      ooo                                           ooo
     |     oo                                               oo
     |    o                                                   o
     |   o                                                     o
     |   o                                                     o
     |   o                                                     o
     |   o                                                     o
     |    o                                                   o
     |     oo                                               oo
     |      oo                                             oo
     |        ooo                                       ooo
     |          ooooo                               ooooo
     |               ooooo                     ooooo
     |                    ooooooooooooooooooooo
-1.1 +
      +-----------------------------------------------------------+->
      -1.1                                                      1.1