JuliaPlots / PlotThemes.jl

Themes for the Julia plotting package Plots.jl
Other
122 stars 29 forks source link

API to create custom themes #68

Closed diegozea closed 1 year ago

diegozea commented 2 years ago

Hi! It looks like, at the moment, we need to use the PlotTheme type to create new themes. However, this type is not exported by PlotThemes. The add_theme function could also be great for that, but it accepts only PlotTheme objects. Maybe, adding the add_theme(name::Symbol; kargs...) and add_theme(name::Symbol, theme::KW) methods could solve the problem of the missing API without requiring to export PlotTheme. What do you think? Cheers

BeastyBlacksmith commented 2 years ago

What usecases do you have in mind for this? Plots.jl already has several mechanisms for setting your own default values. What benefit would an API for a custom (private) theme give you?

diegozea commented 2 years ago

It could help create personal/private themes that are easy to reuse through a codebase; maybe because you want to match the color schemes you have carefully set for your IDE, you need institutional colors, or you need it for a particular project, and you do not think it's worth it to share it. Indeed, you can already do that with the default function; but I felt PlotThemes' API is a little nicer, as you can name themes and work with multiple ones without copying/pasting default calls.

diegozea commented 2 years ago

Makie and Gadfly have similar functionality. I think that exporting PlotTheme will offer a solution that is similar to the one in those packages.

BeastyBlacksmith commented 2 years ago

Indeed, you can already do that with the default function; but I felt PlotThemes' API is a little nicer, as you can name themes and work with multiple ones without copying/pasting default calls.

Can you elaborate a bit on what is nicer API wise? Without it you could do

using Plots
my_defaults = Dict(:linewidth => 3, :markershape => :star)
default(;my_defaults...)
plot(1:5)

Maybe an additional method for default(kw::KW) would also help?

I am fearing a bit that private themes might make people share code relying on those themes without sharing the themes and thus leading to non-reproducible code. But maybe I am overcautious here.

diegozea commented 2 years ago

Thanks, I haven't thought of storing the Dict. In that case, having the default(kw::KW) would help, as the splat operator could be a little difficult for some newcomers to the language. About the private themes, we can add a fallback to :default and make theme give a proper warning message when using :default because of the missing theme. The same problem could happen if the Dict is not shared (undef error).

diegozea commented 2 years ago

Ok, using default doesn't allow setting colorgradient as in PlotThemes:

image

diegozea commented 2 years ago

Another point in favor of exporting PlotTheme is that the keyword argument syntax is a lot nicer than the Dict one.

diegozea commented 2 years ago

P.S.: I have found this when writing a book chapter on theme creation with Plots, Makie, and Gadfly. The Plots example for that chapter is here: https://github.com/PacktPublishing/Interactive-Visualization-with-Julia/blob/aa36c5bc32daa7fd689db82c75b39e29657d2b94/Chapter13/plots_themes.jl At the moment, I am using the fully qualified name for PlotTheme.