I guess it’s because you’re running in Jupyter or Juno, while gpmargins()
and gpranges()
requires an actual gnuplot terminal.
Try run the above code in a simple Julia REPL. Or try the following in Jupyter:
using Gnuplot
x = randn(1000);
y = randn(1000);
# Overall plot margins (normalized in the range 0:1)
margins = (l=0.08, r=0.98, b=0.13, t=0.98)
# Right and top margins of main plot
right, top = 0.8, 0.75
# Gap between main plot and histograms
gap = 0.015
# Axis range
xr = [-3,3]
yr = [-3,3]
# Main plot
@gp "set multiplot"
@gp :- 1 ma=margins rma=right tma=top xr=xr yr=yr :-
@gp :- x y "w p notit" xlab="X" ylab="Y"
# Histogram on X
h = hist(x, nbins=10)
@gp :- 2 ma=margins bma=top+gap rma=right xr=xr yr=[NaN,NaN] :-
@gp :- "set xtics format ''" "set ytics format ''" xlab="" ylab="" :-
bs = fill(h.binsize, length(h.bins));
@gp :- h.bins h.counts./2 bs./2 h.counts./2 "w boxxy notit fs solid 0.4" :-
# Histogram on Y
h = hist(y, nbins=10)
@gp :- 3 ma=margins lma=right+gap tma=top xr=[NaN,NaN] yr=yr :-
@gp :- "unset xrange" :-
bs = fill(h.binsize, length(h.bins));
@gp :- h.counts./2 h.bins h.counts./2 bs./2 "w boxxy notit fs solid 0.4" :-
@gp
Concerning your second question: you have complete flexibility for the horizontal histogram on the top (see set style histogram
in the gnuplot manual), while for the vertical histogram on the right you need to calculate the bounding coordinates of each histogram "bar, and use the color/filling properties of the boxxyerror
style.