Skip to content

Commit

Permalink
issue1126
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattriks committed Jul 14, 2018
1 parent 3071ad6 commit 5fe2311
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 13 deletions.
23 changes: 16 additions & 7 deletions docs/src/gallery/geometries.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,22 @@ plot(dataset("Zelig", "macro"), x="Year", y="Country", color="GDP", Geom.rectbin
## [`Geom.ribbon`](@ref)

```@example
using Gadfly, DataFrames
set_default_plot_size(14cm, 8cm)
xs = 0:0.1:20
df_cos = DataFrame(x=xs, y=cos(xs), ymin=cos(xs).-0.5, ymax=cos(xs).+0.5, f="cos")
df_sin = DataFrame(x=xs, y=sin(xs), ymin=sin(xs).-0.5, ymax=sin(xs).+0.5, f="sin")
df = vcat(df_cos, df_sin)
plot(df, x=:x, y=:y, ymin=:ymin, ymax=:ymax, color=:f, Geom.line, Geom.ribbon)
using Gadfly, Colors, DataFrames, Distributions
set_default_plot_size(21cm, 8cm)
X = [cos.(0:0.1:20) sin.(0:0.1:20)]
Da = [DataFrame(x=0:0.1:20, y=X[:,j], ymin=X[:,j].-0.5, ymax=X[:,j].+0.5, f="$f") for (j,f) in enumerate(["cos","sin"])]
Db = [DataFrame(x=x, ymax=pdf.(Normal(μ),x), ymin=0.0, u="μ=$μ") for μ in [-1,1] ]
# In the line below, 0.4 is the color opacity
p1 = plot(vcat(Da...), x=:x, y=:y, ymin=:ymin, ymax=:ymax, color=:f, Geom.line, Geom.ribbon,
Theme(lowlight_color=c->RGBA{Float32}(c.r, c.g, c.b, 0.4))
)
p2 = plot(vcat(Db...), x = :x, y=:ymax, ymin = :ymin, ymax = :ymax, color = :u,
Geom.line, Geom.ribbon, Guide.ylabel("Density"),
Theme(lowlight_color=c->RGBA{Float32}(c.r, c.g, c.b, 0.4)),
Guide.colorkey(title="", pos=[2.5,0.6]), Guide.title("Parametric PDF")
)
hstack(p1,p2)
```


Expand Down
22 changes: 22 additions & 0 deletions docs/src/gallery/statistics.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ p2 = plot(dataset("datasets", "iris"), x="SepalLength", y="SepalWidth",
hstack(p1,p2)
```

## [`Stat.density`](@ref)

```@example
using Colors, DataFrames, Gadfly, Distributions
set_default_plot_size(21cm, 8cm)
x = -4:0.1:4
Da = [DataFrame(x=x, ymax=pdf.(Normal(μ),x), ymin=0.0, u="μ=$μ") for μ in [-1,1]]
Db = [DataFrame(x=randn(200)+μ, u="μ=$μ") for μ in [-1,1]]
p1 = plot(vcat(Da...), x=:x, y=:ymax, ymin=:ymin, ymax=:ymax, color=:u,
Geom.line, Geom.ribbon, Guide.ylabel("Density"),
Theme(lowlight_color=c->RGBA{Float32}(c.r, c.g, c.b, 0.4)),
Guide.colorkey(title="", pos=[2.5,0.6]), Guide.title("Parametric PDF")
)
p2 = plot(vcat(Db...), x=:x, color=:u,
Stat.density(bandwidth=0.5), Geom.polygon(fill=true, preserve_order=true),
Coord.cartesian(xmin=-4, xmax=4),
Theme(lowlight_color=c->RGBA{Float32}(c.r, c.g, c.b, 0.4)),
Guide.colorkey(title="", pos=[2.5,0.6]), Guide.title("Kernel PDF")
)
hstack(p1,p2)
```

## [`Stat.qq`](@ref)

Expand Down
4 changes: 1 addition & 3 deletions docs/src/man/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ These parameters can either be used with `Theme` or `style`
to outline plot geometry. This is a function that alters (e.g. darkens) the
fill color of the geometry. (Function)
* `lowlight_color`: Color used to draw background geometry, such as
`Geom.ribbon`. This is a function that alters the fill color of the geometry.
`Geom.ribbon` and `Geom.polygon`. This is a function that alters the fill color of the geometry.
(Function)
* `lowlight_opacity`: Opacity of background geometry such as [`Geom.ribbon`](@ref).
(Float64)
* `middle_color`: Color altering function used to draw the midline in
boxplots. (Function)
* `middle_width`: Width of the middle line in boxplots. (Measure)
Expand Down
2 changes: 1 addition & 1 deletion src/geom/polygon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function render(geom::PolygonGeometry, theme::Gadfly.Theme,
for c in keys(xs)], geom.tag))
cs = collect(keys(xs))
if geom.fill
compose!(ctx, fill(cs),
compose!(ctx, fill([theme.lowlight_color(c) for c in cs]),
stroke(map(theme.discrete_highlight_color, cs)))
else
compose!(ctx, fill(nothing), stroke(cs))
Expand Down
81 changes: 79 additions & 2 deletions src/theme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ end
# Geom.ribbon in particular so lines stand out against it.
lowlight_color, Function, default_lowlight_color

# Opacity of geometry filled with lowlight_color
lowlight_opacity, Float64, 0.6

# A function mapping base fill color to the color of the median marker in a
# boxplot.
Expand Down Expand Up @@ -393,3 +391,82 @@ end
A light foreground on a dark background.
"""
get_theme(::Val{:dark}) = dark_theme



# Outer constructor for Theme argument depwarns

function Theme(;
default_color::ColorOrNothing=LCHab(70, 60, 240),
point_size::Measure=0.9mm,
point_size_min::Measure=0.45mm,
point_size_max::Measure=1.8mm,
point_shapes::Vector{Function}=[Shape.circle, Shape.square, Shape.diamond, Shape.cross, Shape.xcross, Shape.utriangle, Shape.dtriangle, Shape.star1, Shape.star2, Shape.hexagon, Shape.octagon, Shape.hline, Shape.vline],
line_width::Measure=0.3mm,
line_style::Union{Symbol,Vector}=:solid,
panel_fill::ColorOrNothing=nothing,
panel_stroke::ColorOrNothing=nothing,
panel_opacity::Float64=1.0,
background_color::ColorOrNothing=nothing,
plot_padding::(Vector{<:Measure})=[5mm],
grid_color::ColorOrNothing=colorant"#D0D0E0",
grid_line_style::Union{Symbol,Vector}=[0.5mm, 0.5mm],
grid_color_focused::ColorOrNothing=colorant"#A0A0A0",
grid_line_width::Measure=0.2mm,
minor_label_font::AbstractString=label_font_desc,
minor_label_font_size::Measure=8pt,
minor_label_color::ColorOrNothing=colorant"#6c606b",
major_label_font::AbstractString=title_font_desc,
major_label_font_size::Measure=11pt,
major_label_color::ColorOrNothing=colorant"#564a55",
point_label_font::AbstractString=label_font_desc,
point_label_font_size::Measure=8pt,
point_label_color::ColorOrNothing=colorant"#4c404b",
key_title_font::AbstractString=title_font_desc,
key_title_font_size::Measure=11pt,
key_title_color::ColorOrNothing=colorant"#362a35",
key_label_font::AbstractString=title_font_desc,
key_label_font_size::Measure=8pt,
key_label_color::ColorOrNothing=colorant"#4c404b",
key_color_gradations::Int=40,
bar_spacing::Measure=-0.05mm,
boxplot_spacing::Measure=1mm,
errorbar_cap_length::Measure=3mm,
stroke_color::Function=default_stroke_color,
highlight_width::Measure=0.3mm,
discrete_highlight_color::Function=default_discrete_highlight_color,
continuous_highlight_color::Function=default_continuous_highlight_color,
lowlight_color::Function=default_lowlight_color,
lowlight_opacity::Float64=NaN,
middle_color::Function=default_middle_color,
middle_width::Measure=0.6mm,
guide_title_position::Symbol=:left,
colorkey_swatch_shape::Symbol=:square,
key_swatch_shape::Function=Shape.square,
key_swatch_color::ColorOrNothing=nothing,
key_position::Symbol=:right,
bar_highlight::Union{(Void), Function, Color}=nothing,
rug_size::Measure=2.0mm,
label_placement_iterations::Int=1000,
label_out_of_bounds_penalty::Float64=10.0,
label_hidden_penalty::Float64=0.5,
label_visibility_flip_pr::Float64=0.2,
label_padding::Measure=1mm,
key_max_columns::Int=4,
discrete_color_scale::Scale.DiscreteColorScale=Scale.color_discrete(),
continuous_color_scale::Scale.ContinuousColorScale=Scale.color_continuous()
)

isfinite(lowlight_opacity) && Base.depwarn("The keyword argument `lowlight_opacity` has been deprecated, and never worked anyway!", :Theme)

return Theme(default_color, point_size, point_size_min, point_size_max, point_shapes, line_width, line_style, panel_fill, panel_stroke, panel_opacity, background_color,
plot_padding, grid_color, grid_line_style, grid_color_focused, grid_line_width,
minor_label_font, minor_label_font_size, minor_label_color, major_label_font, major_label_font_size, major_label_color,
point_label_font, point_label_font_size, point_label_color, key_title_font, key_title_font_size, key_title_color, key_label_font, key_label_font_size, key_label_color,
key_color_gradations, bar_spacing, boxplot_spacing, errorbar_cap_length, stroke_color, highlight_width, discrete_highlight_color, continuous_highlight_color,
lowlight_color, middle_color, middle_width, guide_title_position, colorkey_swatch_shape, key_swatch_shape, key_swatch_color, key_position, bar_highlight,
rug_size, label_placement_iterations, label_out_of_bounds_penalty, label_hidden_penalty, label_visibility_flip_pr, label_padding, key_max_columns,
discrete_color_scale, continuous_color_scale)

end

0 comments on commit 5fe2311

Please sign in to comment.