Skip to content

Instantly share code, notes, and snippets.

@mdibaiee
Created October 1, 2016 09:36
Show Gist options
  • Save mdibaiee/257b0cc3d76875457c4c5bb432d8a4fe to your computer and use it in GitHub Desktop.
Save mdibaiee/257b0cc3d76875457c4c5bb432d8a4fe to your computer and use it in GitHub Desktop.
Plotting Text

It's possible to plot text on chart using Plot.Annotation:

annotation chart

import Graphics.Rendering.Chart
import Graphics.Rendering.Chart.Backend.Cairo
import Data.Default.Class
import Control.Lens

ws = [(1, 5, "hello"), (2, 3, "chart"), (3, 2, "diagram"), (3, 3, "text"), (4, 1, "annotation"), (2, 2, "plot")] :: [(Int, Int, String)]

chart = toRenderable layout
  where
    layout = layout_title .~ "texts"
           $ layout_plots .~ [toPlot texts]
           $ def

    texts = plot_annotation_values .~ ws
          $ plot_annotation_angle .~ 20 -- degrees
          $ plot_annotation_style .~ fontStyle
          $ plot_annotation_hanchor .~ HTA_Centre -- the horizontal anchor around which the text is rotated
          $ plot_annotation_vanchor .~ VTA_Centre -- the vertical anchor
          $ def

    fontStyle = font_size .~ 15
              $ font_weight .~ FontWeightBold
              $ def

main = renderableToFile def "chart.png" chart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment