Skip to content

Commit 5fe2311

Browse files
committed
issue1126
1 parent 3071ad6 commit 5fe2311

File tree

5 files changed

+119
-13
lines changed

5 files changed

+119
-13
lines changed

docs/src/gallery/geometries.md

+16-7
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,22 @@ plot(dataset("Zelig", "macro"), x="Year", y="Country", color="GDP", Geom.rectbin
344344
## [`Geom.ribbon`](@ref)
345345

346346
```@example
347-
using Gadfly, DataFrames
348-
set_default_plot_size(14cm, 8cm)
349-
xs = 0:0.1:20
350-
df_cos = DataFrame(x=xs, y=cos(xs), ymin=cos(xs).-0.5, ymax=cos(xs).+0.5, f="cos")
351-
df_sin = DataFrame(x=xs, y=sin(xs), ymin=sin(xs).-0.5, ymax=sin(xs).+0.5, f="sin")
352-
df = vcat(df_cos, df_sin)
353-
plot(df, x=:x, y=:y, ymin=:ymin, ymax=:ymax, color=:f, Geom.line, Geom.ribbon)
347+
using Gadfly, Colors, DataFrames, Distributions
348+
set_default_plot_size(21cm, 8cm)
349+
X = [cos.(0:0.1:20) sin.(0:0.1:20)]
350+
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"])]
351+
Db = [DataFrame(x=x, ymax=pdf.(Normal(μ),x), ymin=0.0, u="μ=$μ") for μ in [-1,1] ]
352+
353+
# In the line below, 0.4 is the color opacity
354+
p1 = plot(vcat(Da...), x=:x, y=:y, ymin=:ymin, ymax=:ymax, color=:f, Geom.line, Geom.ribbon,
355+
Theme(lowlight_color=c->RGBA{Float32}(c.r, c.g, c.b, 0.4))
356+
)
357+
p2 = plot(vcat(Db...), x = :x, y=:ymax, ymin = :ymin, ymax = :ymax, color = :u,
358+
Geom.line, Geom.ribbon, Guide.ylabel("Density"),
359+
Theme(lowlight_color=c->RGBA{Float32}(c.r, c.g, c.b, 0.4)),
360+
Guide.colorkey(title="", pos=[2.5,0.6]), Guide.title("Parametric PDF")
361+
)
362+
hstack(p1,p2)
354363
```
355364

356365

docs/src/gallery/statistics.md

+22
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,28 @@ p2 = plot(dataset("datasets", "iris"), x="SepalLength", y="SepalWidth",
1212
hstack(p1,p2)
1313
```
1414

15+
## [`Stat.density`](@ref)
16+
17+
```@example
18+
using Colors, DataFrames, Gadfly, Distributions
19+
set_default_plot_size(21cm, 8cm)
20+
x = -4:0.1:4
21+
Da = [DataFrame(x=x, ymax=pdf.(Normal(μ),x), ymin=0.0, u="μ=$μ") for μ in [-1,1]]
22+
Db = [DataFrame(x=randn(200)+μ, u="μ=$μ") for μ in [-1,1]]
23+
24+
p1 = plot(vcat(Da...), x=:x, y=:ymax, ymin=:ymin, ymax=:ymax, color=:u,
25+
Geom.line, Geom.ribbon, Guide.ylabel("Density"),
26+
Theme(lowlight_color=c->RGBA{Float32}(c.r, c.g, c.b, 0.4)),
27+
Guide.colorkey(title="", pos=[2.5,0.6]), Guide.title("Parametric PDF")
28+
)
29+
p2 = plot(vcat(Db...), x=:x, color=:u,
30+
Stat.density(bandwidth=0.5), Geom.polygon(fill=true, preserve_order=true),
31+
Coord.cartesian(xmin=-4, xmax=4),
32+
Theme(lowlight_color=c->RGBA{Float32}(c.r, c.g, c.b, 0.4)),
33+
Guide.colorkey(title="", pos=[2.5,0.6]), Guide.title("Kernel PDF")
34+
)
35+
hstack(p1,p2)
36+
```
1537

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

docs/src/man/themes.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,8 @@ These parameters can either be used with `Theme` or `style`
7676
to outline plot geometry. This is a function that alters (e.g. darkens) the
7777
fill color of the geometry. (Function)
7878
* `lowlight_color`: Color used to draw background geometry, such as
79-
`Geom.ribbon`. This is a function that alters the fill color of the geometry.
79+
`Geom.ribbon` and `Geom.polygon`. This is a function that alters the fill color of the geometry.
8080
(Function)
81-
* `lowlight_opacity`: Opacity of background geometry such as [`Geom.ribbon`](@ref).
82-
(Float64)
8381
* `middle_color`: Color altering function used to draw the midline in
8482
boxplots. (Function)
8583
* `middle_width`: Width of the middle line in boxplots. (Measure)

src/geom/polygon.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function render(geom::PolygonGeometry, theme::Gadfly.Theme,
109109
for c in keys(xs)], geom.tag))
110110
cs = collect(keys(xs))
111111
if geom.fill
112-
compose!(ctx, fill(cs),
112+
compose!(ctx, fill([theme.lowlight_color(c) for c in cs]),
113113
stroke(map(theme.discrete_highlight_color, cs)))
114114
else
115115
compose!(ctx, fill(nothing), stroke(cs))

src/theme.jl

+79-2
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,6 @@ end
158158
# Geom.ribbon in particular so lines stand out against it.
159159
lowlight_color, Function, default_lowlight_color
160160

161-
# Opacity of geometry filled with lowlight_color
162-
lowlight_opacity, Float64, 0.6
163161

164162
# A function mapping base fill color to the color of the median marker in a
165163
# boxplot.
@@ -393,3 +391,82 @@ end
393391
A light foreground on a dark background.
394392
"""
395393
get_theme(::Val{:dark}) = dark_theme
394+
395+
396+
397+
# Outer constructor for Theme argument depwarns
398+
399+
function Theme(;
400+
default_color::ColorOrNothing=LCHab(70, 60, 240),
401+
point_size::Measure=0.9mm,
402+
point_size_min::Measure=0.45mm,
403+
point_size_max::Measure=1.8mm,
404+
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],
405+
line_width::Measure=0.3mm,
406+
line_style::Union{Symbol,Vector}=:solid,
407+
panel_fill::ColorOrNothing=nothing,
408+
panel_stroke::ColorOrNothing=nothing,
409+
panel_opacity::Float64=1.0,
410+
background_color::ColorOrNothing=nothing,
411+
plot_padding::(Vector{<:Measure})=[5mm],
412+
grid_color::ColorOrNothing=colorant"#D0D0E0",
413+
grid_line_style::Union{Symbol,Vector}=[0.5mm, 0.5mm],
414+
grid_color_focused::ColorOrNothing=colorant"#A0A0A0",
415+
grid_line_width::Measure=0.2mm,
416+
minor_label_font::AbstractString=label_font_desc,
417+
minor_label_font_size::Measure=8pt,
418+
minor_label_color::ColorOrNothing=colorant"#6c606b",
419+
major_label_font::AbstractString=title_font_desc,
420+
major_label_font_size::Measure=11pt,
421+
major_label_color::ColorOrNothing=colorant"#564a55",
422+
point_label_font::AbstractString=label_font_desc,
423+
point_label_font_size::Measure=8pt,
424+
point_label_color::ColorOrNothing=colorant"#4c404b",
425+
key_title_font::AbstractString=title_font_desc,
426+
key_title_font_size::Measure=11pt,
427+
key_title_color::ColorOrNothing=colorant"#362a35",
428+
key_label_font::AbstractString=title_font_desc,
429+
key_label_font_size::Measure=8pt,
430+
key_label_color::ColorOrNothing=colorant"#4c404b",
431+
key_color_gradations::Int=40,
432+
bar_spacing::Measure=-0.05mm,
433+
boxplot_spacing::Measure=1mm,
434+
errorbar_cap_length::Measure=3mm,
435+
stroke_color::Function=default_stroke_color,
436+
highlight_width::Measure=0.3mm,
437+
discrete_highlight_color::Function=default_discrete_highlight_color,
438+
continuous_highlight_color::Function=default_continuous_highlight_color,
439+
lowlight_color::Function=default_lowlight_color,
440+
lowlight_opacity::Float64=NaN,
441+
middle_color::Function=default_middle_color,
442+
middle_width::Measure=0.6mm,
443+
guide_title_position::Symbol=:left,
444+
colorkey_swatch_shape::Symbol=:square,
445+
key_swatch_shape::Function=Shape.square,
446+
key_swatch_color::ColorOrNothing=nothing,
447+
key_position::Symbol=:right,
448+
bar_highlight::Union{(Void), Function, Color}=nothing,
449+
rug_size::Measure=2.0mm,
450+
label_placement_iterations::Int=1000,
451+
label_out_of_bounds_penalty::Float64=10.0,
452+
label_hidden_penalty::Float64=0.5,
453+
label_visibility_flip_pr::Float64=0.2,
454+
label_padding::Measure=1mm,
455+
key_max_columns::Int=4,
456+
discrete_color_scale::Scale.DiscreteColorScale=Scale.color_discrete(),
457+
continuous_color_scale::Scale.ContinuousColorScale=Scale.color_continuous()
458+
)
459+
460+
isfinite(lowlight_opacity) && Base.depwarn("The keyword argument `lowlight_opacity` has been deprecated, and never worked anyway!", :Theme)
461+
462+
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,
463+
plot_padding, grid_color, grid_line_style, grid_color_focused, grid_line_width,
464+
minor_label_font, minor_label_font_size, minor_label_color, major_label_font, major_label_font_size, major_label_color,
465+
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,
466+
key_color_gradations, bar_spacing, boxplot_spacing, errorbar_cap_length, stroke_color, highlight_width, discrete_highlight_color, continuous_highlight_color,
467+
lowlight_color, middle_color, middle_width, guide_title_position, colorkey_swatch_shape, key_swatch_shape, key_swatch_color, key_position, bar_highlight,
468+
rug_size, label_placement_iterations, label_out_of_bounds_penalty, label_hidden_penalty, label_visibility_flip_pr, label_padding, key_max_columns,
469+
discrete_color_scale, continuous_color_scale)
470+
471+
end
472+

0 commit comments

Comments
 (0)