Chart-1.9.3: A library for generating 2D Charts and Plots

Copyright(c) Tim Docker 2014
LicenseBSD-style (see chart/COPYRIGHT)
Safe HaskellNone
LanguageHaskell98

Graphics.Rendering.Chart.Easy

Description

A high level API for generating a plot quickly.

Importing the Easy module brings into scope all core functions and types required for working with the chart library. This includes key external dependencies such as Control.Lens and Data.Colour. The module also provides several helper functions for quickly generating common plots. Note that chart backends must still be explicitly imported, as some backends cannot be built on all platforms.

Example usage:

import Graphics.Rendering.Chart.Easy
import Graphics.Rendering.Chart.Backend.Cairo

signal :: [Double] -> [(Double,Double)]
signal xs = [ (x,(sin (x*3.14159/45) + 1) / 2 * (sin (x*3.14159/5))) | x <- xs ]

main = toFile def "example.png" $ do
    layout_title .= "Amplitude Modulation"
    plot (line "am" [signal [0,(0.5)..400]])
    plot (points "am points" (signal [0,7..400]))

More examples can be found on the library's wiki

Synopsis

Documentation

alphaChannel :: AlphaColour a -> a #

Returns the opacity of an AlphaColour.

atop :: Fractional a => AlphaColour a -> AlphaColour a -> AlphaColour a #

c1 `atop` c2 returns the AlphaColour produced by covering the portion of c2 visible by c1. The resulting alpha channel is always the same as the alpha channel of c2.

c1 `atop` (opaque c2) == c1 `over` (opaque c2)
AlphaChannel (c1 `atop` c2) == AlphaChannel c2

blend :: (Num a, AffineSpace f) => a -> f a -> f a -> f a #

Compute the weighted average of two points. e.g.

blend 0.4 a b = 0.4*a + 0.6*b

The weight can be negative, or greater than 1.0; however, be aware that non-convex combinations may lead to out of gamut colours.

withOpacity :: Num a => Colour a -> a -> AlphaColour a #

Creates an AlphaColour from a Colour with a given opacity.

c `withOpacity` o == dissolve o (opaque c) 

dissolve :: Num a => a -> AlphaColour a -> AlphaColour a #

Returns an AlphaColour more transparent by a factor of o.

opaque :: Num a => Colour a -> AlphaColour a #

Creates an opaque AlphaColour from a Colour.

alphaColourConvert :: (Fractional b, Real a) => AlphaColour a -> AlphaColour b #

Change the type used to represent the colour coordinates.

transparent :: Num a => AlphaColour a #

This AlphaColour is entirely transparent and has no associated colour channel.

black :: Num a => Colour a #

colourConvert :: (Fractional b, Real a) => Colour a -> Colour b #

Change the type used to represent the colour coordinates.

data Colour a #

This type represents the human preception of colour. The a parameter is a numeric type used internally for the representation.

The Monoid instance allows one to add colours, but beware that adding colours can take you out of gamut. Consider using blend whenever possible.

Instances
AffineSpace Colour 
Instance details

Defined in Data.Colour.Internal

Methods

affineCombo :: Num a => [(a, Colour a)] -> Colour a -> Colour a #

ColourOps Colour 
Instance details

Defined in Data.Colour.Internal

Methods

over :: Num a => AlphaColour a -> Colour a -> Colour a #

darken :: Num a => a -> Colour a -> Colour a #

Eq a => Eq (Colour a) 
Instance details

Defined in Data.Colour.Internal

Methods

(==) :: Colour a -> Colour a -> Bool #

(/=) :: Colour a -> Colour a -> Bool #

Num a => Semigroup (Colour a) 
Instance details

Defined in Data.Colour.Internal

Methods

(<>) :: Colour a -> Colour a -> Colour a #

sconcat :: NonEmpty (Colour a) -> Colour a #

stimes :: Integral b => b -> Colour a -> Colour a #

Num a => Monoid (Colour a) 
Instance details

Defined in Data.Colour.Internal

Methods

mempty :: Colour a #

mappend :: Colour a -> Colour a -> Colour a #

mconcat :: [Colour a] -> Colour a #

data AlphaColour a #

This type represents a Colour that may be semi-transparent.

The Monoid instance allows you to composite colours.

x `mappend` y == x `over` y

To get the (pre-multiplied) colour channel of an AlphaColour c, simply composite c over black.

c `over` black
Instances
AffineSpace AlphaColour 
Instance details

Defined in Data.Colour.Internal

Methods

affineCombo :: Num a => [(a, AlphaColour a)] -> AlphaColour a -> AlphaColour a #

ColourOps AlphaColour 
Instance details

Defined in Data.Colour.Internal

Methods

over :: Num a => AlphaColour a -> AlphaColour a -> AlphaColour a #

darken :: Num a => a -> AlphaColour a -> AlphaColour a #

Eq a => Eq (AlphaColour a) 
Instance details

Defined in Data.Colour.Internal

Num a => Semigroup (AlphaColour a)

AlphaColour forms a monoid with over and transparent.

Instance details

Defined in Data.Colour.Internal

Num a => Monoid (AlphaColour a) 
Instance details

Defined in Data.Colour.Internal

class AffineSpace (f :: Type -> Type) where #

Methods

affineCombo :: Num a => [(a, f a)] -> f a -> f a #

Compute a affine Combination (weighted-average) of points. The last parameter will get the remaining weight. e.g.

affineCombo [(0.2,a), (0.3,b)] c == 0.2*a + 0.3*b + 0.5*c

Weights can be negative, or greater than 1.0; however, be aware that non-convex combinations may lead to out of gamut colours.

Instances
AffineSpace Colour 
Instance details

Defined in Data.Colour.Internal

Methods

affineCombo :: Num a => [(a, Colour a)] -> Colour a -> Colour a #

AffineSpace AlphaColour 
Instance details

Defined in Data.Colour.Internal

Methods

affineCombo :: Num a => [(a, AlphaColour a)] -> AlphaColour a -> AlphaColour a #

class ColourOps (f :: Type -> Type) where #

Minimal complete definition

over, darken

Methods

darken :: Num a => a -> f a -> f a #

darken s c blends a colour with black without changing it's opacity.

For Colour, darken s c = blend s c mempty

Instances
ColourOps Colour 
Instance details

Defined in Data.Colour.Internal

Methods

over :: Num a => AlphaColour a -> Colour a -> Colour a #

darken :: Num a => a -> Colour a -> Colour a #

ColourOps AlphaColour 
Instance details

Defined in Data.Colour.Internal

Methods

over :: Num a => AlphaColour a -> AlphaColour a -> AlphaColour a #

darken :: Num a => a -> AlphaColour a -> AlphaColour a #

line :: String -> [[(x, y)]] -> EC l (PlotLines x y) #

Constuct a line plot with the given title and data, using the next available color.

points :: String -> [(x, y)] -> EC l (PlotPoints x y) #

Construct a scatter plot with the given title and data, using the next available color and point shape.

bars :: (PlotValue x, BarsPlotValue y) => [String] -> [(x, [y])] -> EC l (PlotBars x y) #

Construct a bar chart with the given titles and data, using the next available colors

setColors :: [AlphaColour Double] -> EC l () #

Set the contents of the colour source, for subsequent plots

setShapes :: [PointShape] -> EC l () #

Set the contents of the shape source, for subsequent plots