by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 00:13
    Mattriks commented #1471
  • Aug 11 23:46

    tlnagy on gh-pages

    build based on 2b240fd (compare)

  • Aug 11 23:06

    Mattriks on master

    flag Scale.color_none for depre… (compare)

  • Aug 11 23:06
    Mattriks closed #1469
  • Aug 11 23:06
    Mattriks closed #527
  • Aug 11 23:00
    Mattriks edited #1469
  • Aug 11 15:59
    dehann commented #1471
  • Aug 11 05:11
    dehann commented #1470
  • Aug 11 05:10
    dehann commented #1470
  • Aug 11 05:03
    dehann commented #1470
  • Aug 11 05:02
    dehann commented #1470
  • Aug 11 05:02
    dehann commented #1470
  • Aug 11 05:00
    dehann commented #1470
  • Aug 11 04:59
    dehann commented #1470
  • Aug 11 04:58
    dehann commented #1470
  • Aug 11 04:53
    dehann commented #1470
  • Aug 11 04:52
    dehann commented #1470
  • Aug 11 04:52
    dehann commented #1470
  • Aug 11 03:28
    Mattriks commented #1471
  • Aug 11 03:18
    dehann commented #1471
you can add style( ) to the layer with Stat.qq
Júlio Hoffimann
@juliohm
This is what I am doing to set my custom theme based off the default theme:
theme = Gadfly.get_theme(Val(:default))
Gadfly.push_theme(theme)
theme = style(point_size=2.5px, key_position=:top)
Is this the recommended way? I then tried to pass default_color="red" to the style to customise it further but it didn't work
BTW, I think the Val(:default) syntax could be simplified to just :default in the get_theme call. New Julia users will struggle figuring out what Val is.
Mattriks
@Mattriks
Oh I forgot about that, with style you have to do:
layer(x=x, y=y, Stat.qq, style(default_color=colorant"red"))
Júlio Hoffimann
@juliohm
Awesome, it worked. Please let me know if there is a cleaner method to customise the default theme.
Regarding the LOESS ribbon option, it shows the confidence bands, right? I've implemented the deviation bands in LocallyWeightedRegression.jl, but I think the derivation assumes Gaussian errors AFAIR: https://nbviewer.jupyter.org/github/JuliaEarth/LocallyWeightedRegression.jl/blob/master/docs/Usage.ipynb
Mattriks
@Mattriks
I'm not sure which "LOESS ribbon option shows the confidence bands". Do you mean in theory, or in R?
Júlio Hoffimann
@juliohm
As I understand it, confidence bands can be obtained with bootstrap as explained in that issue. We resample the original points with replace and recompute the loess estimates. We then take .95 pointwise quantile for example to build a confidence upper bound. On the other hand, we can also have an analytical estimate of conditional variance like I did in LocallyWeightedRegression.jl if we assume Gaussian errors. The latter would already be useful for visualization in my opinion. If you can point out which part of the code computes the ribbon in Gadfly, I can try submit a PR.
Mattriks
@Mattriks
The standard errors should be calculated in loess.jl (not in Gadfly). There are fast approximation methods e.g. https://doi.org/10.1007/BF01890836 (without bootstrapping)
Júlio Hoffimann
@juliohm
Will check if I can submit a PR there
Júlio Hoffimann
@juliohm
How to add text on top of a Geom.hline? I have a horizontal with a theoretical threshold in a plot, and so it would be nice to add some short text explaining what it means like Binomial limit
Mattriks
@Mattriks
Geom.label)? Use "line1\nline2" for multiline labels.
Mattriks
@Mattriks
Re: Stat.qq, I started PR #1434
Júlio Hoffimann
@juliohm
Thank you Mattriks will take a look at the plots again to incorporate your suggestions.
Júlio Hoffimann
@juliohm
@Mattriks regarding the Geom.label, I think I am trying to use Guide.annotation instead, but can't figure out from the documentation how to annotate a horizontal line produced with Geom.hline for example.
Mattriks
@Mattriks
plot(yintercept=[0.5], Geom.hline,
   x=[1.0], y=[0.5], label=["horizontal line"], Geom.label(position=:above)
)
Júlio Hoffimann
@juliohm
Thank you for you help. Will try it locally here.
Júlio Hoffimann
@juliohm

I have the following plot:

plot(df, x=Col.value(xcols...), y=:ACTUAL,
       xgroup=Col.index(xcols...), ygroup=:MODEL,
       color=:config,
       Geom.subplot_grid(layer(Geom.point), free_x_axis=true,
                         layer(yintercept=[0.0], Geom.hline(color=colors[1], style=:dash)),
                         layer(yintercept=[0.5], Geom.hline(color=colors[3], style=:dash)),
                         Coord.cartesian(ymax=0.5),
                         Guide.ylabel(orientation=:vertical)))

Tried adding the Geom.label to the last layer after the call to Geom.hline but it didn't work.

Mattriks
@Mattriks
For Geom.subplot grid, you need to do something like this:
Mattriks
@Mattriks
# in the DataFrame add label as a string or vector of strings
df2 = DataFrame(xg=["kldiv", "jaccard", "areashift"], x=rand(3), y=0.5, label="line text")
# add this layer to subplot_grid 
layer(df2, x=:x, y=:y, label=:label, xgroup=:xg, Geom.label(position=:above))
See Facets in the docs. I plan to do more work on subplot_grid after #1385.
Júlio Hoffimann
@juliohm
Thank you. Will try tomorrow when I get back to the computer.
Mattriks
@Mattriks
When using layers with multiple dataframes with subplot_grid, you may also need to use Scale.xgroup(levels=["kldiv","jaccard","areashift"]) to ensure the xgroups are ordered correctly for each dataframe (if the xgroups happen to be in the same order, things should be ok).
Júlio Hoffimann
@juliohm
Thank you I'll definitely double check that
Júlio Hoffimann
@juliohm

How do you give different label for multiple functions?

plot([sin, cos], 0, 1, label=["sin", "cos"])

didn't work. Should it work?

Mattriks
@Mattriks
plot([sin, cos], 0, 1, color=["sin", "cos"])
To understand why, see the example plot in #1420
Júlio Hoffimann
@juliohm
Thank you it worked :)
Nicholas Ritchie
@NicholasWMRitchie
I had filed (and subsequently closed) a bug report on the curious behavior I'm seeing with Gadfly 1.3.0 / Colors 0.12.2. I thought I'd beaten it but its back.
I'm using
Guide.manual_color_key(...)
I know I'm passing in a Colorant[ ], not a RGB[...], even though the contents is RGB{Float64}. I can
@assert eltype(colors)==Colorant
However, by the time it works its way through the system I get an error:
TypeError: in new, expected Array{ColorTypes.Colorant,1}, got Array{ColorTypes.RGB{Float64},1}
Nicholas Ritchie
@NicholasWMRitchie
It is as though the Array type is being mutated along the way. Now a RGB is a Colorant so there should be no problem their. Previously, I had passed in a mixed Colorant[] containing both RGB and Lab colors. This caused a entirely different issue. An
"in ccolor, abstract intersection between Color and Color{Float64,3}"
error. I can't even find reference to what an "abstract intersection" even is.
I'm currently tearing my hair out. I'd have thought I should be able to hand in a RGB[...]. Very confused.
Nicholas Ritchie
@NicholasWMRitchie
Any thoughts would be gratefully appreciated!
Nicholas Ritchie
@NicholasWMRitchie
Here is the relevant code:
    @assert eltype(palette[1:length(specs)])==Colorant
    Gadfly.with_theme(style) do
        plot(
            layers...,
            Guide.XLabel("Energy (eV)"),
            Guide.YLabel(ylbl),
            Scale.x_continuous(format = :plain),
            Scale.y_continuous(format = :plain),
            Guide.manual_color_key(length(specs) > 1 ? "Spectra" : "Spectrum", names, palette[1:length(specs)]),
            Coord.Cartesian(ymin = 0, ymax = ytransform(yscale * maxI), xmin = convert(Float64,xmin), xmax = maxE),
        )
    end
Nicholas Ritchie
@NicholasWMRitchie
The full error is
ERROR: TypeError: in new, expected Array{Colorant,1}, got Array{RGB{Float64},1}
Stacktrace:
 [1] Gadfly.Guide.ManualDiscreteKey(::String, ::Array{String,1}, ::Array{Any,1}, ::Array{RGB{Float64},1}, ::Array{Function,1}, ::Array{Measures.Measure,1}, ::Bool) at C:\Users\nritchie\.julia\packages\Gadfly\USbaq\src\guide\keys.jl:267
 [2] Gadfly.Guide.ManualDiscreteKey(; title::String, labels::Array{String,1}, pos::Array{Any,1}, color::Array{Colorant,1}, shape::Array{Function,1}, size::Array{Measures.Measure,1}) at C:\Users\nritchie\.julia\packages\Gadfly\USbaq\src\guide\keys.jl:295
 [3] #manual_color_key#131 at C:\Users\nritchie\.julia\packages\Gadfly\USbaq\src\guide\keys.jl:321 [inlined]
 [4] manual_color_key at C:\Users\nritchie\.julia\packages\Gadfly\USbaq\src\guide\keys.jl:321 [inlined]
 [5] (::NeXLSpectrum.var"#489#503"{Float64,Float64,typeof(identity),Array{Colorant,1},Tuple{Spectrum{Float64},Spectrum{Float64}},String,Array{String,1},Array{Layer,1}})() at C:\Users\nritchie\.julia\dev\NeXLSpectrum\src\gadflysupport.jl:244
 [6] with_theme(::NeXLSpectrum.var"#489#503"{Float64,Float64,typeof(identity),Array{Colorant,1},Tuple{Spectrum{Float64},Spectrum{Float64}},String,Array{String,1},Array{Layer,1}}, ::Theme) at C:\Users\nritchie\.julia\packages\Gadfly\USbaq\src\theme.jl:347
 [7] plot(::Spectrum{Float64}, ::Vararg{Spectrum{Float64},N} where N; klms::Array{Any,1}, edges::Array{Any,1}, escapes::Array{Any,1}, coincidences::Array{Any,1}, autoklms::Bool, xmin::Float64, xmax::Float64, norm::NoScaling, yscale::Float64, ytransform::typeof(identity), style::Theme, palette::Array{Colorant,1}, customlayers::Array{Layer,1}) at C:\Users\nritchie\.julia\dev\NeXLSpectrum\src\gadflysupport.jl:243
 [8] top-level scope at C:\Users\nritchie\.julia\packages\Weave\AL87K\src\run.jl:0
Nicholas Ritchie
@NicholasWMRitchie
All appears fine until the step 2 -> 1 when I believe parse_colorant(c::Union{Tuple,Vector}) = [parse_colorant(x) for x in c] is taking a Colorant[] and returning a RGB[].
Mattriks
@Mattriks
This example works for me:
palette = [RGB(1,0,0), RGB(0,1,0)]
names, specs = randstring.([4, 5]), [1,2]

Gadfly.with_theme(style()) do
p = plot(Geom.blank,
    Guide.XLabel("Energy (eV)"), Guide.YLabel("ylbl"),
    Scale.x_continuous(format = :plain),   Scale.y_continuous(format = :plain),
    Guide.manual_color_key(length(specs) > 1 ? "Spectra" : "Spectrum", names, palette[1:length(specs)]),
#    Coord.Cartesian(ymin = 0, ymax = ytransform(yscale * maxI), xmin = convert(Float64,xmin), xmax = maxE)
)
end
Nicholas Ritchie
@NicholasWMRitchie

I'm really confused. The color argument is a ::Array{Colorant,1} in stacktrace [2] but becomes an ::Array{RGB{Float64},1} in stacktrace [2] in the error message above. I believe this is because it is passed through parse_colorant(...) which Compose says parse_colorant(c::Union{Tuple,Vector}) = [parse_colorant(x) for x in c]. This does in fact convert a ::Array{Colorant,1} to a ::Array{RGB{Float64},1} like this:

cols=Compose.parse_colorant(Colorant[ RGB(1,0,0), RGB(0,1,0) ])
 2-element Array{RGB{N0f8},1} with eltype RGB{FixedPointNumbers.Normed{UInt8,8}}:
 RGB{N0f8}(1.0,0.0,0.0)
 RGB{N0f8}(0.0,1.0,0.0)

Now Gadfly.Guide.ManualDiscreteKey(...) takes an ::Array{Colorant,1} not a ::Array{RGB,1} or an ::Array{<:Colorant,1} and when handed a Array{RGB,1} I see it fail. (I don't understand why you don't.)

If there is in fact a problem, there would be two ways to resolve this:

# In Compose, add Colorant to the return array definition
parse_colorant(c::Union{Tuple,Vector}) = Colorant[parse_colorant(x) for x in c]
# In Gadfly, change color::Array{Colorant,1} to color::Array{<:Colorant,1}
Gadfly.Guide.ManualDiscreteKey(; title::String, labels::Array{String,1}, pos::Array{Any,1}, color::Array{<:Colorant,1}, shape::Array{Function,1}, size::Array{Measures.Measure,1})

The Compose change is more likely to cause other problems. The Gadfly change is more focused.

However, while I see a problem, you don't and I can't figure out what in my code is causing the difference in results. That is why I closed the bug report but none-the-less believe there is something wrong here. I just can't put my finger on it.

Nicholas Ritchie
@NicholasWMRitchie

I have solved my problem by adding

Gadfly.parse_colorant(c::Array{Colorant,1}) = c

to my code. If someone else reports the problem, you might considering adding similar code to Compose.jl.

Thanks for your patience.

Mattriks
@Mattriks
I don't think it's correct to say that "Gadfly.ManualDiscreteKey(...) takes an ::Array{Colorant, 1}". A constructor converts any of its arguments into it's specified fieldtypes, and here's an example:
struct mytype
   i::Float64    
end
mytype(1)
Nicholas Ritchie
@NicholasWMRitchie

I believe that you are correct. However, that doesn't explain the error I see.

ERROR: TypeError: in new, expected Array{Colorant,1}, got Array{RGB{Float64},1}
Stacktrace:
    [1] Gadfly.Guide.ManualDiscreteKey(::String, ::Array{String,1}, ::Array{Any,1}, ::Array{RGB{Float64},1}, ::Array{Function,1}, ::Array{Measures.Measure,1}, ::Bool) at C:\Users\nritchie\.julia\packages\Gadfly\USbaq\src\guide\keys.jl:267

Why isn't the Array{RGB{Float64},1} being converted to an Array{Colorant,1} as you indicate it should...
Which suggests to me that there is something deeper going on. (I don't want to say compiler issue but???)

Mattriks
@Mattriks
In your post https://github.com/GiovineItalia/Gadfly.jl/issues/1454#issuecomment-643618204 you say the basic example works. Is your package code available?
Alan Crawford
@alancrawford
Hi, I am wondering if it is possible to add chart titles onto subplots in Gadfly?
Mattriks
@Mattriks
Not yet, but you can do something like this:
using RDatasets
data = dataset("datasets", "CO2")
labels=["Title 1", "Title 2", "Title 3","Title 4" ]
titledata = DataFrame(label=labels, x=500, y=58, 
    Type=unique(data.Type)[[1,2,1,2]], Treatment=unique(data.Treatment)[[1,1,2,2]] )
coord = Coord.cartesian(ymin=0, ymax=60)

p = plot(data, xgroup=:Type, ygroup=:Treatment,
Geom.subplot_grid(coord,
    layer(data, x=:Conc, y=:Uptake,  xgroup=:Type, ygroup=:Treatment, Geom.point),
    layer(titledata, x=:x, y=:y, label=:label, xgroup=:Type, ygroup=:Treatment, Geom.label(position=:centered)),
    Guide.yticks(ticks=collect(0:10:50))
),       
    Guide.title("Title of Plot"), Guide.xlabel("Concentration"), Guide.ylabel("Uptake"))
Alan Crawford
@alancrawford
Thanks.