-
-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
PlotThemes
into monorepo (#5015)
- Loading branch information
Showing
20 changed files
with
800 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The PlotThemes.jl package is licensed under the MIT "Expat" License: | ||
|
||
> Copyright (c) 2016: Patrick Kofod Mogensen. | ||
> | ||
> Permission is hereby granted, free of charge, to any person obtaining a copy | ||
> of this software and associated documentation files (the "Software"), to deal | ||
> in the Software without restriction, including without limitation the rights | ||
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
> copies of the Software, and to permit persons to whom the Software is | ||
> furnished to do so, subject to the following conditions: | ||
> | ||
> The above copyright notice and this permission notice shall be included in all | ||
> copies or substantial portions of the Software. | ||
> | ||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
> SOFTWARE. | ||
> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name = "PlotThemes" | ||
uuid = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a" | ||
version = "3.3.0" | ||
|
||
[deps] | ||
PlotUtils = "995b91a9-d308-5afd-9ec6-746e21dbc043" | ||
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" | ||
|
||
[compat] | ||
PlotUtils = "1" | ||
julia = "1" | ||
|
||
[extras] | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
test = ["Test"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# PlotThemes | ||
|
||
[![Build Status](https://travis-ci.org/JuliaPlots/PlotThemes.jl.svg?branch=master)](https://travis-ci.org/JuliaPlots/PlotThemes.jl) | ||
|
||
#### Primary author: Patrick Kofod Mogensen (@pkofod) | ||
|
||
PlotThemes is a package to spice up the plots made with [Plots.jl](https://github.com/JuliaPlots/Plots.jl). To install: | ||
|
||
```julia | ||
Pkg.add("PlotThemes") | ||
``` | ||
|
||
## Using PlotThemes | ||
|
||
Currently the following themes are available: | ||
- `:default` | ||
- `:dark` | ||
- `:ggplot2` | ||
- `:juno` | ||
- `:lime` | ||
- `:orange` | ||
- `:sand` | ||
- `:solarized` | ||
- `:solarized_light` | ||
- `:wong` | ||
- `:wong2` | ||
- `:gruvbox_dark` | ||
- `:gruvbox_light` | ||
- `:bright` | ||
- `:vibrant` | ||
- `:mute` | ||
- `:dao` | ||
- `:dracula` | ||
- `:rose_pine` | ||
- `:rose_pine_dawn` | ||
|
||
|
||
When using Plots, a theme can be set using the `theme` function: | ||
```julia | ||
using Plots | ||
theme(thm::Symbol; kwargs...) | ||
``` | ||
`theme` accepts any Plots [attribute](https://docs.juliaplots.org/stable/attributes/) as keyword argument and sets its value as default for subsequent plots. | ||
|
||
Themes can be previewed using `Plots.showtheme(thm::Symbol)`: | ||
|
||
### `:default` | ||
![theme_default](https://user-images.githubusercontent.com/16589944/70847841-7ca7ea00-1e69-11ea-851e-e99d8559260d.png) | ||
|
||
### `:dark` | ||
![theme_dark](https://user-images.githubusercontent.com/16589944/70847843-8d586000-1e69-11ea-9e39-5d4c44865750.png) | ||
|
||
### `:ggplot2` | ||
![theme_ggplot2](https://user-images.githubusercontent.com/16589944/70847847-99442200-1e69-11ea-9ae8-ddd10ec4a303.png) | ||
|
||
### `:juno` | ||
![theme_juno](https://user-images.githubusercontent.com/16589944/70847860-be389500-1e69-11ea-88b9-2a3bb3bbcf64.png) | ||
|
||
### `:lime` | ||
![theme_lime](https://user-images.githubusercontent.com/16589944/70847863-c55fa300-1e69-11ea-8de7-3ef2a3a8ce30.png) | ||
|
||
### `:orange` | ||
![theme_orange](https://user-images.githubusercontent.com/16589944/70847866-cf81a180-1e69-11ea-813a-7e4394311ef2.png) | ||
|
||
### `:sand` | ||
![theme_sand](https://user-images.githubusercontent.com/16589944/70847868-d4deec00-1e69-11ea-8aab-de94af02bbfe.png) | ||
|
||
### `:solarized` | ||
![theme_solarized](https://user-images.githubusercontent.com/16589944/70847869-dad4cd00-1e69-11ea-930e-b145e19bcff5.png) | ||
|
||
### `:solarized_light` | ||
![theme_solarized_light](https://user-images.githubusercontent.com/16589944/70847872-df998100-1e69-11ea-955a-7fcc2e7043de.png) | ||
|
||
### `:wong` | ||
![theme_wong](https://user-images.githubusercontent.com/16589944/70847875-e58f6200-1e69-11ea-904d-d4f7e27bb181.png) | ||
|
||
### `:wong2` | ||
![theme_wong2](https://user-images.githubusercontent.com/16589944/70847880-eaecac80-1e69-11ea-9b59-cdf937427121.png) | ||
|
||
### `:gruvbox_dark` | ||
![theme_gruvbox_dark](https://user-images.githubusercontent.com/16589944/70847882-f049f700-1e69-11ea-94f8-255f2cd17288.png) | ||
|
||
### `:gruvbox_light` | ||
![theme_gruvbox_light](https://user-images.githubusercontent.com/16589944/70847885-fb048c00-1e69-11ea-9546-4dc0d9e4154c.png) | ||
|
||
### `:bright` | ||
![theme_bright](https://user-images.githubusercontent.com/16589944/70848065-8ed75780-1e6c-11ea-8e59-9882b3c4a4db.png) | ||
|
||
### `:vibrant` | ||
![theme_vibrant](https://user-images.githubusercontent.com/16589944/70848066-926ade80-1e6c-11ea-91ba-fd08d14e6963.png) | ||
|
||
### `:mute` | ||
![theme_mute](https://user-images.githubusercontent.com/16589944/70848069-9860bf80-1e6c-11ea-9cac-8a797d526835.png) | ||
|
||
### `:dao` | ||
![theme_dao](https://user-images.githubusercontent.com/7330605/106512313-54de7000-64c9-11eb-98d5-2aee3603879a.png) | ||
|
||
### `:dracula` | ||
![theme_dracula](https://user-images.githubusercontent.com/64332767/136754217-31d4348a-c873-4496-8b66-905e4d8a7e36.png) | ||
|
||
### `:rose_pine` | ||
![theme_rose_pine](https://github.com/BaerLKR/PlotThemes.jl/assets/83340886/30c869e5-2b90-405a-bc49-cf4ef3c43d75) | ||
|
||
### `:rose_pine_dawn` | ||
![theme_rose_pine_dawn](https://github.com/BaerLKR/PlotThemes.jl/assets/83340886/e30c0b46-1be3-49f5-afc5-ceede0b0c27d) | ||
|
||
## Contributing | ||
A theme specifies default values for different Plots [attributes](https://docs.juliaplots.org/stable/attributes/). | ||
At the moment these are typically colors, palettes and colorgradients, but any Plots attribute can be controlled by a theme in general. | ||
PRs for new themes very welcome! Adding a new theme (e.g. `mytheme`) is as easy as adding a new file (mytheme.jl) that contains at least the following line: | ||
```julia | ||
_themes[:mytheme] = PlotTheme(; kwargs...) | ||
``` | ||
The keyword arguments can be any collection of Plots attributes plus a colorgradient keyword argument. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
module PlotThemes | ||
|
||
using PlotUtils | ||
|
||
export add_theme, theme_palette, PlotTheme | ||
|
||
_255_to_1(c::Symbol, colors) = RGBA(map(x-> x/255,colors[c])...) | ||
RGB255(r,g,b) = RGB(r/255, g/255, b/255) | ||
|
||
function expand_palette(bg, cs; kwargs...) | ||
colors = palette(cs).colors.colors | ||
c = convert.(RGBA, distinguishable_colors(20, vcat(bg, colors); kwargs...))[2:end] | ||
return palette(c) | ||
end | ||
|
||
const KW = Dict{Symbol, Any} | ||
|
||
struct PlotTheme | ||
defaults::KW | ||
end | ||
|
||
PlotTheme(; kw...) = PlotTheme(KW(kw)) | ||
|
||
# adjust an existing theme | ||
PlotTheme(base::PlotTheme; kw...) = PlotTheme(KW(base.defaults..., KW(kw)...)) | ||
|
||
"Get the palette of a PlotTheme" | ||
function theme_palette(s::Symbol) | ||
if haskey(_themes, s) && haskey(_themes[s].defaults, :palette) | ||
return _themes[s].defaults[:palette] | ||
else | ||
return palette(:default) | ||
end | ||
end | ||
|
||
|
||
# add themes | ||
include("dark.jl") | ||
include("ggplot2.jl") | ||
include("solarized.jl") | ||
include("sand.jl") | ||
include("lime.jl") | ||
include("orange.jl") | ||
include("wong.jl") | ||
include("boxed.jl") | ||
include("juno.jl") | ||
include("gruvbox.jl") | ||
include("sheet.jl") | ||
include("dao.jl") | ||
include("dracula.jl") | ||
include("rose_pine.jl") | ||
|
||
|
||
const _themes = Dict{Symbol, PlotTheme}([ | ||
:default => PlotTheme(), | ||
:dao => _dao, | ||
:dark => _dark, | ||
:ggplot2 => _ggplot2, | ||
:gruvbox_light => _gruvbox_light, | ||
:gruvbox_dark => _gruvbox_dark, | ||
:solarized => _solarized, | ||
:solarized_light => _solarized_light, | ||
:sand => _sand, | ||
:bright => _bright, | ||
:vibrant => _vibrant, | ||
:mute => _mute, | ||
:wong => _wong, | ||
:wong2 => _wong2, | ||
:boxed => _boxed, | ||
:juno => _juno, | ||
:lime => _lime, | ||
:orange => _orange, | ||
:dracula => _dracula, | ||
:rose_pine => _rose_pine, | ||
:rose_pine_dawn => _rose_pine_dawn | ||
|
||
]) | ||
|
||
|
||
function add_theme(s::Symbol, thm::PlotTheme) | ||
_themes[s] = thm | ||
end | ||
|
||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const _boxed = PlotTheme(Dict([ | ||
:minorticks => true, | ||
:grid => false, | ||
:frame => :box, | ||
:guidefontvalign => :top, | ||
:guidefonthalign => :right, | ||
:foreground_color_legend => nothing, | ||
:legendfontsize => 9, | ||
:legend => :topright, | ||
:xlim => (:auto,:auto), | ||
:ylim => (:auto,:auto), | ||
:label => "", | ||
:palette => expand_palette(colorant"white", [RGB(0,0,0); wong_palette]; | ||
lchoices = [57], | ||
cchoices = [100]) | ||
])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const dao_palette = [ | ||
colorant"#d77255", | ||
colorant"#009afa", | ||
colorant"#707070", | ||
colorant"#21ab74", | ||
colorant"#ba3030", | ||
colorant"#9467bd" | ||
] | ||
|
||
const _dao = PlotTheme(Dict([ | ||
:background => :white, | ||
:framestyle => :box, | ||
:grid => true, | ||
:gridalpha => 0.4, | ||
:linewidth => 1.4, | ||
:markerstrokewidth => 0, | ||
:fontfamily => "Computer Modern", | ||
:colorgradient => :magma, | ||
:guidefontsize => 12, | ||
:titlefontsize => 12, | ||
:tickfontsize => 8, | ||
:palette => dao_palette, | ||
:minorgrid => true, | ||
:minorticks => 5, | ||
:gridlinewidth => 0.7, | ||
:minorgridalpha => 0.06, | ||
:legend => :outertopright]) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#inspired by nucleus theme for Atom | ||
const dark_palette = [ | ||
colorant"#FE4365", # red | ||
colorant"#eca25c", # orange | ||
colorant"#3f9778", # green | ||
colorant"#005D7F" # blue | ||
] | ||
const dark_bg = colorant"#363D46" | ||
|
||
const _dark = PlotTheme(Dict([ | ||
:bg => dark_bg, | ||
:bginside => colorant"#30343B", | ||
:fg => colorant"#ADB2B7", | ||
:fgtext => colorant"#FFFFFF", | ||
:fgguide => colorant"#FFFFFF", | ||
:fglegend => colorant"#FFFFFF", | ||
:legendfontcolor => colorant"#FFFFFF", | ||
:legendtitlefontcolor => colorant"#FFFFFF", | ||
:titlefontcolor => colorant"#FFFFFF", | ||
:palette => expand_palette(dark_bg, dark_palette; lchoices = [57], cchoices = [100]), | ||
:colorgradient => :fire]) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Names follow: | ||
# https://draculatheme.com/contribute#color-palette | ||
const dracula_palette = [ | ||
colorant"#8be9fd" # Cyan | ||
colorant"#ff79c6" # Pink | ||
colorant"#50fa7b" # Green | ||
colorant"#bd93f9" # Purple | ||
colorant"#ffb86c" # Orange | ||
colorant"#ff5555" # Red | ||
colorant"#f1fa8c" # Yellow | ||
colorant"#6272a4" # Comment | ||
] | ||
const dracula_bg = colorant"#282a36" | ||
const dracula_fg = colorant"#f8f8f2" | ||
|
||
const _dracula = PlotTheme(Dict([ | ||
:bg => dracula_bg, | ||
:bginside => colorant"#30343B", | ||
:fg => dracula_fg, | ||
:fgtext => dracula_fg, | ||
:fgguide => dracula_fg, | ||
:fglegend => dracula_fg, | ||
:legendfontcolor => dracula_fg, | ||
:legendtitlefontcolor => dracula_fg, | ||
:titlefontcolor => dracula_fg, | ||
:palette => expand_palette(dracula_bg, dracula_palette), | ||
:colorgradient => :viridis]) | ||
) |
Oops, something went wrong.