plots-0.1.1.1: Diagrams based plotting library.

Copyright(C) 2015 Christopher Chalmers
LicenseBSD-style (see the file LICENSE)
MaintainerChristopher Chalmers
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Plots.Types.Bar

Contents

Description

A bar plot is a plot that presents data with rectangular bars with lengths proportional to the values that they represent. The bars can be plotted vertically or horizontally.

(see multiBars example for code to make this plot)

Synopsis

BarPlot

data BarPlot Source #

A bar plot for a single set of bars. Multi-bar plots are achieved by having multiple BarPlots. Each bar plot corresponds to a single legend entry. To get multiple bar entries/colours, use multiple BarPlots

Instances
Enveloped BarPlot Source # 
Instance details

Defined in Plots.Types.Bar

Methods

getEnvelope :: BarPlot -> Envelope (V BarPlot) (N BarPlot)

boundingBox :: BarPlot -> BoundingBox (V BarPlot) (N BarPlot)

HasOrientation BarPlot Source # 
Instance details

Defined in Plots.Types.Bar

Plotable BarPlot Source # 
Instance details

Defined in Plots.Types.Bar

Methods

renderPlotable :: InSpace v Double BarPlot => AxisSpec v -> PlotStyle v -> BarPlot -> Diagram v Source #

defLegendPic :: InSpace v Double BarPlot => PlotStyle v -> BarPlot -> Diagram v Source #

HasBarLayout BarPlot Source # 
Instance details

Defined in Plots.Types.Bar

type N BarPlot Source # 
Instance details

Defined in Plots.Types.Bar

type N BarPlot = Double
type V BarPlot Source # 
Instance details

Defined in Plots.Types.Bar

type V BarPlot = V2

barPlot Source #

Arguments

:: (MonadState (Axis V2) m, Foldable f) 
=> f Double

bar heights

-> State (Plot BarPlot) ()

changes to the bars

-> m ()

changes to the Axis

A add BarPlot to an Axis.

Example

Expand

import Plots
barAxis :: Axis B V2 Double
barAxis = r2Axis &~ do
  yMin ?= 0
  hide majorGridLines
  barPlot [13.5, 3.0, 6.9, 7.2, 4.6] $ do
    vertical .= True
    barWidth //= 2
barExample = renderAxis barAxis

barPlot' Source #

Arguments

:: (MonadState (Axis V2) m, Foldable f) 
=> f Double

bar heights

-> m ()

changes to the Axis

Simple version of barPlot without any modification to the Plot.

Example

Expand

import Plots
barAxis' :: Axis B V2 Double
barAxis' = r2Axis &~ do
  xMin ?= 0
  hide (yAxis . majorGridLines)
  barPlot' [13.5, 3.0, 6.9, 7.2, 4.6]
barExample' = renderAxis barAxis'

namedBarPlot Source #

Arguments

:: (MonadState (Axis V2) m, Foldable f) 
=> f (String, Double)

bar heights with name

-> State (Plot BarPlot) ()

changes to the bars

-> m ()

changes to the Axis

A add BarPlot to an Axis while naming the bars.

Example

Expand

import Plots
namedBarAxis :: Axis B V2 Double
namedBarAxis = r2Axis &~ do
  yMin ?= 0
  hide (xAxis . majorGridLines)
  namedBarPlot [("eggs", 12), ("bacon", 5), ("sausage", 9), ("beans", 3)] $ do
    vertical .= True
    barWidth //= 2

namedBarExample = renderAxis namedBarAxis

namedBarPlot' Source #

Arguments

:: (MonadState (Axis V2) m, Foldable f) 
=> f (String, Double)

bar heights with name

-> m ()

add plot to the Axis

Simple version of namedBarPlot without any modification to the Plot.

Example

Expand

import Plots
namedBarAxis' :: Axis B V2 Double
namedBarAxis' = r2Axis &~ do
  xMin ?= 0
  hide majorGridLines
  namedBarPlot' [("eggs", 12), ("bacon", 5), ("sausage", 9), ("beans", 3)]
namedBarExample' = renderAxis namedBarAxis'

floatingBarPlot Source #

Arguments

:: (MonadState (Axis V2) m, Foldable f) 
=> f (Double, Double)

bar limits

-> State (Plot BarPlot) ()

changes to the bars

-> m () 

Same as barPlot but with lower and upper bounds for the bars.

Bar layout

data BarLayout Source #

The way an individual bar plot or a group of bars plots are laid out on the axis.

class HasOrientation a => HasBarLayout a where Source #

Class of things that have a modifiable BarLayout.

Minimal complete definition

barLayout

Methods

barLayout :: Lens' a BarLayout Source #

Lens onto the BarLayout

barWidth :: Lens' a Double Source #

The width bar for single / stacked bars or the width of a group for grouped bar plot.

Default is 0.8

barSpacing :: Lens' a Double Source #

The spacing between each bar or group of bars.

Default is 1

barStart :: Lens' a Double Source #

The distance from the axis to centre of the first bar.

Default is 1

Multi bars

Adding to axis

multiBars Source #

Arguments

:: (MonadState (Axis V2) m, Foldable f, Foldable g) 
=> f a

data for multi plot

-> (a -> g Double)

extract bar heights from each data set

-> State (MultiBarState a) ()

state to make changes to the plot

-> m ()

changes to the Axis

Construct multiple bars, grouped together. See MultiBarState for details on how to customise how the bars are drawn.

Example

Expand

import Plots
breakfastData :: [(String, V2 Double)]
breakfastData = [("eggs", V2 7 5), ("bacon", V2 5 4), ("sausage", V2 2 7), ("beans", V2 2 1)]
sortedData = [ ("girls", breakfastData^..each._2._x)
             , ("boys",  breakfastData^..each._2._y)
             ]
multiBarAxis :: Axis B V2 Double
multiBarAxis = r2Axis &~ do
  yMin ?= 0
  hide (xAxis . majorGridLines)
  hide minorTicks
  xLabel .= "breakfast item"
  multiBars sortedData snd $ do
    vertical .= True
    barWidth //= 2
    labelBars (map fst breakfastData)
    onBars $ \(nm,_) -> key nm

  -- show y values without decimal point
  yAxis . tickLabelFunction .= atMajorTicks (show . round)
  -- we should really force all major ticks to like on integers too
multiBarExample = renderAxis multiBarAxis

data MultiBarState a Source #

The MultiBarState is used to set the various options available when building multiple bar plots together. The main functions used to modify this state:

Multi bar types

groupedBars :: State (MultiBarState a) () Source #

Bars that are grouped together such that each group is a single barWidth. The bars in a group are touching, see groupedBars' to reduce the width of individual bars.

Example

Expand

groupedBars' :: Double -> State (MultiBarState a) () Source #

Bars that are grouped together such that each group is a single barWidth. The parameter is the multiplier for the width of individual bars, where groupedBars 1 = groupedBars corresponds to bars in a group touching. reduce the width of individual bars.

Example

Expand

stackedBars :: State (MultiBarState a) () Source #

Bars stacked on top of each other.

Example

Expand

stackedEqualBars :: Double -> State (MultiBarState a) () Source #

Bars stacked on top of each other where every bar is the given height.

Example

Expand

runningBars :: State (MultiBarState a) () Source #

Normal bars where each data set follows the last.

Example

Expand

Modify multi bars

onBars Source #

Arguments

:: (a -> State (PlotMods V2) ())

Modifier the PlotOptions and PlotStyle for the bars associated with the data from a.

-> State (MultiBarState a) ()

Changes to each data set when executing multiBars.

Given the data for the bar, modify the properties for the bar that uses that data.

Some common functions to use on the PlotMods:

  • plotColour - change the colour of the bars
  • areaStyle - modify the style of the bars
  • key - add a legend entry for that group of bars

labelBars :: HasLabels a => [String] -> State a () Source #

Labels to use for each bar (or group of bars) along the axis.

Low level constructors

mkBars :: Foldable f => BarLayout -> f Double -> BarPlot Source #

Create equidistant bars using the values.

mkFloatingBars :: Foldable f => BarLayout -> f (Double, Double) -> BarPlot Source #

Create equidistant bars with lower and upper bounds for each bar.

mkRunningBars :: BarLayout -> [[(Double, Double)]] -> [BarPlot] Source #

Create uniform bars from groups of data, placing one group after the other.

mkStackedBars :: BarLayout -> [[Double]] -> [BarPlot] Source #

Create uniform bars from groups of data, placing one on top of the other. The first list will be the same as mkUniformBars opts (map (0,) ys), subsequent lists will be placed on top.

mkStackedEqualBars Source #

Arguments

:: Double

value each bar reaches

-> BarLayout 
-> [[Double]]

values

-> [BarPlot] 

Similar to mkMultiStacked but stack has the same height.

mkGroupedBars Source #

Arguments

:: Double

width factor of individual bars (1 = touching)

-> BarLayout 
-> [[Double]] 
-> [BarPlot] 

Make bars that are grouped together. Each group of bars is treated as a single bar when using the BarPlotsOpts. There is an addition parameter to adjust the width of each individual bar.