hcarty / ocaml-plplot

OCaml bindings for PLplot
https://hcarty.github.io/ocaml-plplot/plplot/plplot/Plplot/index.html
Other
17 stars 9 forks source link

Please Allow Users to Change the Background Color to White Using the Plot or Better QuickPlot Module Functions #6

Open llee454 opened 2 years ago

llee454 commented 2 years ago

The default color scheme (black background with red curves) is visually unappealing. Every other plotting library seems to default to a sensible white background with black curves. Please allow developers to change the background color using the QuickPlot and the Plot modules. Doing so will not break backward compatibility and will vastly improve the visual quality of the output.

Thanks

hcarty commented 2 years ago

This is supported but I don't have any examples in the repo showing how to use it.

The Plot.color_palette_t type is for custom color palettes:

https://github.com/hcarty/ocaml-plplot/blob/5b7e70e091f1827ac5c303ce232eacade35690fb/src/plplot.mli#L118-L119

They can be selected and loaded with with these functions: https://github.com/hcarty/ocaml-plplot/blob/5b7e70e091f1827ac5c303ce232eacade35690fb/src/plplot.mli#L225-L238

An example of how this can be used with the Plot module from a utop/ocaml/down session:

let pre () = Plot.load_palette (Plot.indexed_palette "cmap0_alternate.pal");;
let stream = Plot.init ~filename:"test.png" ~pre (0.0, -2.0) (10.0, 2.0) `equal (`png `cairo);;
Plot.plot ~stream [Plot.func `black sin (0.0, 10.0)];;
Plot.finish ~stream ();;
Plot.end_stream ~stream ();;

That should produce this output: plot output

There are a number of palettes provided by the PLplot library in *.pal files here. I usually use cmap0_alternate.pal. You can also define your own palette if you'd prefer.

A few of the Quick_plot module's functions would need API changes - maybe a pre optional argument to pass on to the internal call to Plot.init - to properly support this as well. I don't use PLplot as much as a I used to but if there's interest I'd be happy to update the Quick_plot API to support this! And/or make the alternate indexed palette the default when using ocaml-plplot.

hcarty commented 2 years ago

Also - apologies for taking so long to respond! I hope the description above is still helpful.