Safe Haskell | None |
---|---|
Language | Haskell2010 |
Matplotlib bindings and an interface to easily bind to new portions of the API. The most essential parts of Matplotlib are wrapped and exposed to Haskell through an interface that allows extenisbility. Code is generated on the fly and python is called.
This is not a very Haskell-ish library. Type safety is non-existent, it's easy to generate incorrect Python code, in exchange for being able to bind to arbitrary matplotlib APIs with ease, so it's also easy to generate correct python code.
The generated code follows a few simple conventions. data is always loaded into a data variable that is a python array. Data is transffered via json. This data variable is indexed by various rendering commands.
Functions which start with the word data operate on the data array, arguments are python code that should access that array. Most other functions take haskell objects and load them into python.
This module should expose enough tools so that you can bind any part of the
matplotlib API. A binding with options, such as that of plot
, looks like:
readData (x, y) % mp a b # ")" % mp label # "')"
Where important functions are:
readData
- Load the given data into the python data array by serializing it to JSON.
%
- Sequence two plots
mp
- Create an empty plot
#
- Append python code to the last command in a plot
##
- Just like
#
but also adds in a placeholder for an options list
You can call this plot with
plot [1,2,3,4,5,6] [1,3,2,5,2] @@ [o1 "'go-'", o2 "linewidth" "2"]
where @@
applies an options list replacing the last ##
Right now there's no easy way to bind to an option other than the last one unless you want to pass options in as parameters.
- onscreen :: Matplotlib -> IO (Either String String)
- code :: Matplotlib -> IO String
- figure :: [Char] -> Matplotlib -> IO (Either String String)
- xacorr :: (ToJSON t, ToJSON a) => a -> t -> [Option] -> Matplotlib
- histogram :: (MplotValue val, ToJSON t) => t -> val -> Matplotlib
- histogram2D :: ToJSON t => t -> t -> Matplotlib
- scatter :: (ToJSON t1, ToJSON t) => t1 -> t -> Matplotlib
- line :: (ToJSON t1, ToJSON t) => t1 -> t -> Matplotlib
- errorbar :: (ToJSON t, ToJSON t1, ToJSON t2) => t2 -> t1 -> t -> Matplotlib
- lineF :: (ToJSON a, ToJSON b) => (a -> b) -> [a] -> Matplotlib
- boxplot :: ToJSON a => a -> Matplotlib
- contourF :: (ToJSON val, MplotValue val, Ord val) => (Double -> Double -> val) -> Double -> Double -> Double -> Double -> Double -> Matplotlib
- projectionsF :: (ToJSON val, MplotValue val, Ord val) => (Double -> Double -> val) -> Double -> Double -> Double -> Double -> Double -> Matplotlib
- plotInterpolated :: (MplotValue val, ToJSON t, ToJSON t1) => t1 -> t -> val -> Matplotlib
- plotMapLinear :: ToJSON b => (Double -> b) -> Double -> Double -> Double -> Matplotlib
- line1 :: (Foldable t, ToJSON (t a)) => t a -> Matplotlib
- matShow :: ToJSON a => a -> Matplotlib
- pcolor :: ToJSON a => a -> Matplotlib
- density :: [Double] -> Maybe (Double, Double) -> Matplotlib
- setTeX :: Bool -> Matplotlib
- setUnicode :: Bool -> Matplotlib
- dataPlot :: (MplotValue val, MplotValue val1) => val1 -> val -> Matplotlib
- plot :: (ToJSON t, ToJSON t1) => t1 -> t -> Matplotlib
- grid :: Bool -> Matplotlib
- dateLine :: (ToJSON t1, ToJSON t2) => t1 -> t2 -> String -> (Int, Int, Int) -> Matplotlib
- xLabel :: MplotValue val => val -> Matplotlib
- yLabel :: MplotValue val => val -> Matplotlib
- zLabel :: MplotValue val => val -> Matplotlib
- dataHistogram :: (MplotValue val1, MplotValue val) => val1 -> val -> Matplotlib
- dataScatter :: (MplotValue val1, MplotValue val) => val1 -> val -> Matplotlib
- dataLine :: (MplotValue val1, MplotValue val) => val1 -> val -> Matplotlib
- contour :: (Foldable t, Foldable t1, Foldable t2, Foldable t3, Foldable t4, Foldable t5, Ord (t val), Ord (t2 val1), Ord (t4 val2), Ord val, Ord val1, Ord val2, MplotValue val, MplotValue val2, MplotValue val1, ToJSON (t1 (t val)), ToJSON (t3 (t2 val1)), ToJSON (t5 (t4 val2))) => t5 (t4 val2) -> t3 (t2 val1) -> t1 (t val) -> Matplotlib
- projections :: (Foldable t, Foldable t1, Foldable t2, Foldable t3, Foldable t4, Foldable t5, Ord (t val), Ord (t2 val1), Ord (t4 val2), Ord val, Ord val1, Ord val2, MplotValue val, MplotValue val2, MplotValue val1, ToJSON (t1 (t val)), ToJSON (t3 (t2 val1)), ToJSON (t5 (t4 val2))) => t5 (t4 val2) -> t3 (t2 val1) -> t1 (t val) -> Matplotlib
- axis3DProjection :: Matplotlib
- wireframe :: (MplotValue val2, MplotValue val1, MplotValue val) => val2 -> val1 -> val -> Matplotlib
- surface :: (MplotValue val2, MplotValue val1, MplotValue val) => val2 -> val1 -> val -> Matplotlib
- contourRaw :: (MplotValue val1, MplotValue val2, MplotValue val5, MplotValue val4, MplotValue val3, MplotValue val) => val5 -> val4 -> val3 -> val2 -> val1 -> val -> Matplotlib
- minimum2 :: (Ord (t a), Ord a, Foldable t1, Foldable t) => t1 (t a) -> a
- maximum2 :: (Ord (t a), Ord a, Foldable t1, Foldable t) => t1 (t a) -> a
- axis3DLabels :: (Foldable t, Foldable t1, Foldable t2, Foldable t3, Foldable t4, Foldable t5, Ord (t val), Ord (t2 val1), Ord (t4 val2), Ord val, Ord val1, Ord val2, MplotValue val, MplotValue val1, MplotValue val2) => t5 (t4 val2) -> t3 (t2 val1) -> t1 (t val) -> Matplotlib
- subplotDataBar :: (MplotValue val, MplotValue val2, MplotValue val1) => val2 -> val1 -> val -> [Option] -> Matplotlib
- addSubplot :: (MplotValue val2, MplotValue val1, MplotValue val) => val2 -> val1 -> val -> Matplotlib
- getSubplot :: (MplotValue val2, MplotValue val1, MplotValue val) => val2 -> val1 -> val -> Matplotlib
- barDefaultWidth :: (Integral a1, Fractional a) => a1 -> a
- subplotBarsLabelled :: (MplotValue val, Foldable t, ToJSON (t a)) => [t a] -> val -> [[Option]] -> Matplotlib
- subplotBars :: ToJSON a => [a] -> [[Option]] -> Matplotlib
- title :: MplotValue val => val -> Matplotlib
- axisXTickSpacing :: (MplotValue val1, MplotValue val) => val1 -> val -> Matplotlib
- axisXTickLabels :: MplotValue val => val -> Matplotlib
- interpolate :: (MplotValue val, MplotValue val2, MplotValue val1) => val2 -> val1 -> val -> Matplotlib
- squareAxes :: Matplotlib
- roateAxesLabels :: MplotValue val => val -> Matplotlib
- verticalAxes :: Matplotlib
- logX :: Matplotlib
- logY :: Matplotlib
- xlim :: (MplotValue val1, MplotValue val) => val1 -> val -> Matplotlib
- ylim :: (MplotValue val1, MplotValue val) => val1 -> val -> Matplotlib
- densityBandwidth :: [Double] -> Double -> Maybe (Double, Double) -> Matplotlib
- axhline :: MplotValue val => val -> Matplotlib
- xcorr :: (ToJSON t, ToJSON t1) => t1 -> t -> Matplotlib
- acorr :: ToJSON a => a -> Matplotlib
- text :: (MplotValue val2, MplotValue val1, MplotValue val) => val2 -> val1 -> val -> Matplotlib
- legend :: Matplotlib
- colorbar :: Matplotlib
- subplots :: Matplotlib
- setSubplot :: MplotValue val => val -> Matplotlib
- data Matplotlib
- data Option
- (@@) :: Matplotlib -> [Option] -> Matplotlib
- (%) :: Matplotlib -> Matplotlib -> Matplotlib
- o1 :: String -> Option
- o2 :: String -> String -> Option
- (##) :: MplotValue val => Matplotlib -> val -> Matplotlib
- (#) :: MplotValue val => Matplotlib -> val -> Matplotlib
- mp :: Matplotlib
- def :: Matplotlib -> [Option] -> Matplotlib
- readData :: ToJSON a => a -> Matplotlib
Running a plot
onscreen :: Matplotlib -> IO (Either String String) Source #
Show a plot, blocks until the figure is closed
Useful plots
xacorr :: (ToJSON t, ToJSON a) => a -> t -> [Option] -> Matplotlib Source #
Plot the cross-correlation and autocorrelation of several variables. TODO Due to a limitation in the options mechanism this takes explicit options.
histogram :: (MplotValue val, ToJSON t) => t -> val -> Matplotlib Source #
Plot a histogram for the given values with bins
histogram2D :: ToJSON t => t -> t -> Matplotlib Source #
Plot a 2D histogram for the given values with bins
scatter :: (ToJSON t1, ToJSON t) => t1 -> t -> Matplotlib Source #
Plot the given values as a scatter plot
errorbar :: (ToJSON t, ToJSON t1, ToJSON t2) => t2 -> t1 -> t -> Matplotlib Source #
Like plot
but takes an error bar value per point
lineF :: (ToJSON a, ToJSON b) => (a -> b) -> [a] -> Matplotlib Source #
Plot a line given a function that will be executed for each element of given list. The list provides the x values, the function the y values.
boxplot :: ToJSON a => a -> Matplotlib Source #
contourF :: (ToJSON val, MplotValue val, Ord val) => (Double -> Double -> val) -> Double -> Double -> Double -> Double -> Double -> Matplotlib Source #
Given a grid of x and y values and a number of steps call the given function and plot the 3D contour
projectionsF :: (ToJSON val, MplotValue val, Ord val) => (Double -> Double -> val) -> Double -> Double -> Double -> Double -> Double -> Matplotlib Source #
Given a grid of x and y values and a number of steps call the given function and plot the 3D projection
plotInterpolated :: (MplotValue val, ToJSON t, ToJSON t1) => t1 -> t -> val -> Matplotlib Source #
Plot x against y interpolating with n steps
plotMapLinear :: ToJSON b => (Double -> b) -> Double -> Double -> Double -> Matplotlib Source #
A handy function to plot a line between two points give a function and a number o steps
line1 :: (Foldable t, ToJSON (t a)) => t a -> Matplotlib Source #
Plot a line between 0 and the length of the array with the given y values
matShow :: ToJSON a => a -> Matplotlib Source #
Plot a matrix
pcolor :: ToJSON a => a -> Matplotlib Source #
Plot a matrix
density :: [Double] -> Maybe (Double, Double) -> Matplotlib Source #
Plot a KDE of the given functions; a good bandwith will be chosen automatically
Matplotlib configuration
setTeX :: Bool -> Matplotlib Source #
setUnicode :: Bool -> Matplotlib Source #
Basic plotting commands
dataPlot :: (MplotValue val, MplotValue val1) => val1 -> val -> Matplotlib Source #
Plot the a
and b
entries of the data object
plot :: (ToJSON t, ToJSON t1) => t1 -> t -> Matplotlib Source #
Plot the Haskell objects x
and y
as a line
grid :: Bool -> Matplotlib Source #
Show/hide grid lines
dateLine :: (ToJSON t1, ToJSON t2) => t1 -> t2 -> String -> (Int, Int, Int) -> Matplotlib Source #
Plot x against y where x is a date.
xunit is something like weeks
, yearStart, monthStart, dayStart are an offset to x.
TODO This isn't general enough; it's missing some settings about the format. The call is also a mess.
xLabel :: MplotValue val => val -> Matplotlib Source #
Add a label to the x axis
yLabel :: MplotValue val => val -> Matplotlib Source #
Add a label to the y axis
zLabel :: MplotValue val => val -> Matplotlib Source #
Add a label to the z axis
dataHistogram :: (MplotValue val1, MplotValue val) => val1 -> val -> Matplotlib Source #
Create a histogram for the a
entry of the data array
dataScatter :: (MplotValue val1, MplotValue val) => val1 -> val -> Matplotlib Source #
Create a scatter plot accessing the given fields of the data array
dataLine :: (MplotValue val1, MplotValue val) => val1 -> val -> Matplotlib Source #
Create a line accessing the given entires of the data array
contour :: (Foldable t, Foldable t1, Foldable t2, Foldable t3, Foldable t4, Foldable t5, Ord (t val), Ord (t2 val1), Ord (t4 val2), Ord val, Ord val1, Ord val2, MplotValue val, MplotValue val2, MplotValue val1, ToJSON (t1 (t val)), ToJSON (t3 (t2 val1)), ToJSON (t5 (t4 val2))) => t5 (t4 val2) -> t3 (t2 val1) -> t1 (t val) -> Matplotlib Source #
Create a 3D contour
projections :: (Foldable t, Foldable t1, Foldable t2, Foldable t3, Foldable t4, Foldable t5, Ord (t val), Ord (t2 val1), Ord (t4 val2), Ord val, Ord val1, Ord val2, MplotValue val, MplotValue val2, MplotValue val1, ToJSON (t1 (t val)), ToJSON (t3 (t2 val1)), ToJSON (t5 (t4 val2))) => t5 (t4 val2) -> t3 (t2 val1) -> t1 (t val) -> Matplotlib Source #
Create a 3D projection
axis3DProjection :: Matplotlib Source #
Enable 3D projection
wireframe :: (MplotValue val2, MplotValue val1, MplotValue val) => val2 -> val1 -> val -> Matplotlib Source #
Plot a 3D wireframe accessing the given elements of the data array
surface :: (MplotValue val2, MplotValue val1, MplotValue val) => val2 -> val1 -> val -> Matplotlib Source #
Plot a 3D surface accessing the given elements of the data array
contourRaw :: (MplotValue val1, MplotValue val2, MplotValue val5, MplotValue val4, MplotValue val3, MplotValue val) => val5 -> val4 -> val3 -> val2 -> val1 -> val -> Matplotlib Source #
Plot a contour accessing the given elements of the data array
minimum2 :: (Ord (t a), Ord a, Foldable t1, Foldable t) => t1 (t a) -> a Source #
Smallest element of a list of lists
maximum2 :: (Ord (t a), Ord a, Foldable t1, Foldable t) => t1 (t a) -> a Source #
Largest element of a list of lists
axis3DLabels :: (Foldable t, Foldable t1, Foldable t2, Foldable t3, Foldable t4, Foldable t5, Ord (t val), Ord (t2 val1), Ord (t4 val2), Ord val, Ord val1, Ord val2, MplotValue val, MplotValue val1, MplotValue val2) => t5 (t4 val2) -> t3 (t2 val1) -> t1 (t val) -> Matplotlib Source #
Label and set limits of a set of 3D axis TODO This is a mess, does both more and less than it claims.
subplotDataBar :: (MplotValue val, MplotValue val2, MplotValue val1) => val2 -> val1 -> val -> [Option] -> Matplotlib Source #
Draw a bag graph in a subplot TODO Why do we need this?
addSubplot :: (MplotValue val2, MplotValue val1, MplotValue val) => val2 -> val1 -> val -> Matplotlib Source #
Create a subplot with the coordinates (r,c,f)
getSubplot :: (MplotValue val2, MplotValue val1, MplotValue val) => val2 -> val1 -> val -> Matplotlib Source #
Access a subplot with the coordinates (r,c,f)
barDefaultWidth :: (Integral a1, Fractional a) => a1 -> a Source #
The default bar with
subplotBarsLabelled :: (MplotValue val, Foldable t, ToJSON (t a)) => [t a] -> val -> [[Option]] -> Matplotlib Source #
Create a set of labelled bars of a given height
subplotBars :: ToJSON a => [a] -> [[Option]] -> Matplotlib Source #
Create a subplot and a set of labelled bars TODO This is a mess..
title :: MplotValue val => val -> Matplotlib Source #
Add a title
axisXTickSpacing :: (MplotValue val1, MplotValue val) => val1 -> val -> Matplotlib Source #
Set the spacing of ticks on the x axis
axisXTickLabels :: MplotValue val => val -> Matplotlib Source #
Set the labels on the x axis
interpolate :: (MplotValue val, MplotValue val2, MplotValue val1) => val2 -> val1 -> val -> Matplotlib Source #
Update the data array to linearly interpolate between array entries
squareAxes :: Matplotlib Source #
Square up the aspect ratio of a plot.
roateAxesLabels :: MplotValue val => val -> Matplotlib Source #
Set the rotation of the labels on the x axis to the given number of degrees
verticalAxes :: Matplotlib Source #
Set the x labels to be vertical
logX :: Matplotlib Source #
Set the x scale to be logarithmic
logY :: Matplotlib Source #
Set the y scale to be logarithmic
xlim :: (MplotValue val1, MplotValue val) => val1 -> val -> Matplotlib Source #
Set limits on the x axis
ylim :: (MplotValue val1, MplotValue val) => val1 -> val -> Matplotlib Source #
Set limits on the y axis
densityBandwidth :: [Double] -> Double -> Maybe (Double, Double) -> Matplotlib Source #
Plot a KDE of the given functions with an optional start/end and a bandwidth h
axhline :: MplotValue val => val -> Matplotlib Source #
Add a horizontal line across the axis
acorr :: ToJSON a => a -> Matplotlib Source #
Plot auto-correlation
text :: (MplotValue val2, MplotValue val1, MplotValue val) => val2 -> val1 -> val -> Matplotlib Source #
Plot text at a specified location
legend :: Matplotlib Source #
Insert a legend
colorbar :: Matplotlib Source #
Insert a color bar
subplots :: Matplotlib Source #
Creates subplots and stores them in an internal variable
setSubplot :: MplotValue val => val -> Matplotlib Source #
Access a subplot
Creating custom plots and applying options
data Matplotlib Source #
The wrapper type for a matplotlib computation.
Throughout the API we need to accept options in order to expose matplotlib's many configuration options.
(@@) :: Matplotlib -> [Option] -> Matplotlib infixl 6 Source #
A combinator for option
that applies a list of options to a plot
(%) :: Matplotlib -> Matplotlib -> Matplotlib infixl 5 Source #
Combine two matplotlib commands
(##) :: MplotValue val => Matplotlib -> val -> Matplotlib infixl 6 Source #
A combinator like #
that also inserts an option
(#) :: MplotValue val => Matplotlib -> val -> Matplotlib infixl 6 Source #
Add Python code to the last matplotlib command
mp :: Matplotlib Source #
Create an empty plot. This the beginning of most plotting commands.
def :: Matplotlib -> [Option] -> Matplotlib Source #
Bind a list of default options to a plot. Positional options are kept in order and default that way as well. Keyword arguments are
readData :: ToJSON a => a -> Matplotlib Source #
Load the given data into the 'data' array