0

I'm trying to plot a very simple bar plot using plot. However, I've gotten stuck with adding strings to the base of the bars along the X-axis.

My attempt:

import Graphics.Rendering.Plot.Figure
import Graphics.Rendering.Plot.Render
import Numeric.LinearAlgebra (vector, Vector)

test_bar :: Figure ()
test_bar = do
    let ts = vector [1..5] :: Vector Double
        ds = vector [1..5] :: Vector Double
        barWidth = 10 :: Double
        barBorder = 2 :: Double

    setPlots 1 1
    withPlot (1,1) $ do
        setDataset (ts,[bar ds (barWidth, grey::Color,barBorder)])
        addAxis XAxis (Side Lower) $ withAxisLabel $ setText "X-axis"
        addAxis YAxis (Side Lower) $ withAxisLabel $ setText "Y-axis"
        setRange XAxis Lower Linear 0 5
        setRange YAxis Lower Linear 0 5

main :: IO ()
main = do writeFigure PNG "bars.png" (w,h) test_bar
    where 
        w = 800
        h = 600

To my understanding, here, ts represent the indices of the X-axis that we place values at, and ds represent the values, or the height of each bar.

How do I add string labels to the X-axis? Such that the display will be "A", "B", "C", etc, instead of "1.00","2.00","3.00" etc.

enter image description here

2
  • ts = vector [1..5], means a vector with 1, 2, 3, 4 and 5. Commented Apr 19, 2024 at 16:30
  • Perhaps you can abuse the tick formatting configuration. Commented Apr 20, 2024 at 3:05

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.