Skip to content

Commit

Permalink
fix kde with PythonPlot/PythonCall
Browse files Browse the repository at this point in the history
  • Loading branch information
marius311 committed Aug 23, 2023
1 parent 2bc85a9 commit dfe2006
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ext/CMBLensingPythonPlotExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ end
# 2D KDE
function PythonPlot.plot(k::CMBLensing.GetDistKDE{2}, args...; color=nothing, label=nothing, levels=[0.95,0.68], filled=true, kwargs...)
@unpack colors = pyimport("matplotlib")
args = k.kde.x, k.kde.y, k.kde.P, [k.kde.getContourLevels(levels); Inf]
args = k.kde.x, k.kde.y, k.kde.P, [pyconvert(Array, k.kde.getContourLevels(levels)); Inf]
if color == nothing
color = gca()._get_lines.get_next_color()
end
filled && contourf(args...; colors=[(colors.to_rgb(color)..., α) for α in (0.4, 0.8)], kwargs...)
filled && contourf(args...; colors=[(pyconvert(Tuple, colors.to_rgb(color))..., α) for α in (0.4, 0.8)], kwargs...)
contour(args...; colors=color, label, kwargs...)
end

Expand Down
3 changes: 2 additions & 1 deletion src/chains.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,10 @@ function kde(samples::AbstractMatrix; boundary=((nothing,nothing),(nothing,nothi
error("KDE only supports 1 or 2 dimensional samples.")
end
getdist = pyimport("getdist")
np = pyimport("numpy")
getdist.chains.print_load_details = false
kde = getdist.MCSamples(;
samples, weights=nothing, names=["x","y"], ranges=Dict("x"=>boundary[1], "y"=>boundary[2])
samples=np.asarray(samples), weights=nothing, names=["x","y"], ranges=Dict("x"=>boundary[1], "y"=>boundary[2])
)
density_kwargs = isnothing(smooth_scale_2D) ? () : (;smooth_scale_2D)
GetDistKDE{2}(kde.get2DDensity(0, 1; density_kwargs...).normalize(normalize))
Expand Down

0 comments on commit dfe2006

Please sign in to comment.