1

我正在尝试通过此示例使用Diagrams 后端(均来自 Stackage)来测试Chart

import Graphics.Rendering.Chart.Easy
import Graphics.Rendering.Chart.Backend.Diagrams

signal :: [Double] -> [(Double,Double)]
signal xs = [ (x,(sin (x*3.14159/45) + 1) / 2 * (sin (x*3.14159/5))) | x <- xs ]

test :: IO ()
test = toFile def "example1_big.png" $ do
    layout_title .= "Amplitude Modulation"
    setColors [opaque blue, opaque red]
    plot (line "am" [signal [0,(0.5)..400]])
    plot (points "am points" (signal [0,7..400]))

来自wiki的example-1

Main.hs文件中

main :: IO ()
main = test

该项目构建和运行没有任何错误,实际上example1_big.png在项目目录中生成了一个文件。但我无法使用feh或任何其他图像查看器打开它。

feh就是说的。

$ feh example1_big.png

feh WARNING: example1_big.png - No Imlib2 loader for that file format
feh: No loadable images specified.
See 'feh --help' or 'man feh' for detailed usage information

使用mediainfo它表明它没有正确的格式信息。

$ mediainfo example1_big.png
General
Complete name                            : example1_big.png
File size                                : 149 KiB

环顾四周,我确实找到了这个线程。本质上,他们建议使用正确定义FileOptions的而不是使用def默认值。

所以这就是我所做的

svgFileOpt :: FileOptions
svgFileOpt = FileOptions (800, 600) SVG loadCommonFonts

signal :: [Double] -> [(Double, Double)]
signal xs =
  [ (x, (sin (x * 3.14159 / 45) + 1) / 2 * (sin (x * 3.14159 / 5))) | x <- xs ]

plotDayVsDouble :: IO ()
plotDayVsDouble = toFile svgFileOpt "example1_big.png" $ do
  layout_title .= "Amplitude Modulation"
  setColors [opaque blue, opaque red]
  plot (line "am" [signal [0, (0.5) .. 400]])
  plot (points "am points" (signal [0, 7 .. 400]))

不幸的是,结果完全相同。我惊讶地发现mediainfo甚至没有显示维度信息。

$ mediainfo example1_big.png

General
Complete name                            : example1_big.png
File size                                : 149 KiB
4

1 回答 1

1

基本上feh,我尝试过的其他图像查看器不支持SVG Scalable Vector Graphics image开箱即用。

使用feh --magick-timeout 1orimagemagickdisplay工作!

于 2020-05-03T10:32:59.040 回答