Can't get marginal plot to work

I’m trying to plot a contour with marginal plots.

I’ve created a user recipe:

@userplot JPlot

@recipe function f(h::JPlot)
    m, x, y = h.args
    mx = vec(sum(m, dims=1))
    my = vec(sum(m, dims=2))
    link := :both
    grid := false
    layout := @layout [t              _
                       c{0.8w, 0.8h}  r]
    # main
    @series begin
        seriestype := :contour
        subplot := 2        
        x, y, m
    seriestype := :line
    # top
    @series begin
        subplot := 1
        x, mx
    # right

    @series begin
        subplot := 3
        orientation := :horizontal        
        y, my

which I tested with:

using Distributions

mv = MvNormal([0, 0], [1 0; 0 1])
xs = range(-3, 3, length=100)
ys = range(-3, 3, length=100)
m = [pdf(mv, [x, y]) for y in ys, x in xs]
jplot(m, xs, ys)

This is what I get:

What happened to the marginal plot on the right?


Update: the problem seems to be with orientation := horizontal

This is fine:

But this isn’t:

what’s going on?

Update: the problem seems to be with orientation := horizontal

It seems that orientation := horizontal is an attribute specific to bar plots. The flip attribute may be more appropriate.

plot(my, ys, yflip =true)

flip, orientation

1 Like

yflip seems to only reverse the y-scale, while a 90 degrees rotation of the plot is here required?

It seems to be a bug, but it should be possible to plot rotated data without rotating the plot.

Is this not the desired output? Though I agree that it does seem to be a bug.

Yes, it is. But not sure it is a result of only :yflip as you have swapped the order of my and y, which amounts to rotate the plot 90-deg.

One could also replace the right-block in the OP’s recipe by:

    seriestype := :shape
    linecolor := :red
    # right
    @series begin
        subplot := 3
        [my; reverse(my)], [y; reverse(y)]

and the output looks alright:

It solves the problem, but this is definitely a hack…