Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
llee454 opened this issue May 4, 2022 · 2 comments

Comments

@llee454
Copy link

llee454 commented May 4, 2022

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
Copy link
Owner

hcarty commented May 30, 2022

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:

ocaml-plplot/src/plplot.mli

Lines 118 to 119 in 5b7e70e

(** A color palette, usually loaded from disk *)
type color_palette_t

They can be selected and loaded with with these functions:

ocaml-plplot/src/plplot.mli

Lines 225 to 238 in 5b7e70e

(** PLplot has two color palettes - indexed (color map 0) and
continuous (color map 1). These functions can be used with
{!load_palette} to set custom indexed and continuous color palettes. *)
val indexed_palette : string -> color_palette_t
(** [continuous_palette ?interpolate filename] - If [interpolate] is true
(the default) then a smooth palette is generated using the color
definitions in the palette file [filename]. Otherwise, the colors
are considered to be discrete, giving a segmented palette. *)
val continuous_palette : ?interpolate:bool -> string -> color_palette_t
(** [load_palette ?stream palette] loads either indexed or continuous
color palette information from a file on disk. *)
val load_palette : ?stream:stream_t -> color_palette_t -> unit

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
Copy link
Owner

hcarty commented May 30, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants