timbod7 / haskell-chart

A 2D charting library for haskell
429 stars 85 forks source link

layout bug (?) when plotting histogram with logarithmic y axis #236

Open rubenmoor opened 2 years ago

rubenmoor commented 2 years ago

image

Those lines going up there are the vertical drop line (I supposed) that all go somewhere top left. This is my code:

plotFrequencies
  :: IO ()
plotFrequencies = do
    ls <- lines <$> readFile "deu_news_2020_freq.txt"
    let ns = tail ls <&> \l -> case splitOn "\t" l of
          [_, n'] -> read $ Text.unpack n'
          _       -> error "missing tab character?"
    renderableToWindow (chart $ dropWhile (> 200) ns) 800 600
  where
    chart
      :: [Double]
      -> Renderable ()
    chart ns =
      toRenderable $ def
        & layout_plots .~ [histogram ns]
        & layout_title .~ "Frequency"
        & layout_x_axis . laxis_generate .~ scaledAxis
            ( def & la_nLabels .~ 200
                  & la_nTicks .~ 200
            ) (1, 200)
        & layout_y_axis . laxis_generate .~ autoScaledLogAxis def

    histogram
      :: [Double]
      -> Plot Double Double
    histogram ns =
      histToPlot $ defaultFloatPlotHist
        & plot_hist_values .~ ns
        & plot_hist_bins .~ 200
        & plot_hist_title .~ "#Total shown: " <> show (length ns)
        & plot_hist_range ?~ (0, 200)