/
hexbin.jl
72 lines (66 loc) · 2.03 KB
/
hexbin.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
###############################################################################
#
# Make hexbin plot
#
###############################################################################
"""
plot_hexbin!(
ax::PyObject,
xs::Array,
ys::Array;
cmap::String = "Greys",
logbins::Bool = false,
gridsize::Number = 25
)
plot_hexbin!(
ax::PyObject,
xs::Array,
ys::Array,
xlims::Array,
ylims::Array;
cmap::String = "Greys",
logbins::Bool = false,
gridsize::Number = 25
)
Plot density plot on axis, given
- `ax` Axis to plot on
- `xs` Array of X
- `ys` Array of Y
- `cmap` Optional. Color map scheme
- `logbins` Optional. If true, use log(count) to color the bins
- `gridsize` Number of bins on both directions
- `xlim` Limits of x axis. Used to make plot region equal among subplots
- `ylim` Limits of y axis. Used to make plot region equal among subplots
"""
function plot_hexbin!(
ax::PyObject,
xs::Array,
ys::Array;
cmap::String = "Greys",
logbins::Bool = false,
gridsize::Number = 25
)
if logbins
return ax.hexbin(xs, ys; cmap=cmap, bins="log", gridsize=gridsize)
end
return ax.hexbin(xs, ys; cmap=cmap, gridsize=gridsize)
end
function plot_hexbin!(
ax::PyObject,
xs::Array,
ys::Array,
xlims::Array,
ylims::Array;
cmap::String = "Greys",
logbins::Bool = false,
gridsize::Number = 25
)
newxs = [collect(xs);
xlims[1] - (xlims[2]-xlims[1]) / 10;
xlims[2] + (xlims[2]-xlims[1]) / 10];
newys = [collect(ys);
ylims[1] - (ylims[2]-ylims[1]) / 10;
ylims[2] + (ylims[2]-ylims[1]) / 10];
return plot_hexbin!(ax, newxs, newys; cmap=cmap, logbins=logbins,
gridsize=gridsize)
end