Skip to content

Commit 0c9ebbf

Browse files
Addimngs 2d histogramm
1 parent 73ff114 commit 0c9ebbf

File tree

2 files changed

+102
-1
lines changed

2 files changed

+102
-1
lines changed

example/components/2D-histogram.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// from http://bl.ocks.org/mbostock/4349187
2+
// Sample from a normal distribution with mean 0, stddev 1.
3+
4+
function normal() {
5+
var x = 0,
6+
y = 0,
7+
rds, c;
8+
do {
9+
x = Math.random() * 2 - 1;
10+
y = Math.random() * 2 - 1;
11+
rds = x * x + y * y;
12+
} while (rds == 0 || rds > 1);
13+
c = Math.sqrt(-2 * Math.log(rds) / rds); // Box-Muller transform
14+
return x * c; // throw away extra sample y * c
15+
}
16+
17+
var N = 2000,
18+
a = -1,
19+
b = 1.2;
20+
21+
var step = (b - a) / (N - 1);
22+
var t = new Array(N), x = new Array(N), y = new Array(N);
23+
24+
for (var i = 0; i < N; i++) {
25+
t[i] = a + step * i;
26+
x[i] = (Math.pow(t[i], 3)) + (0.3 * normal());
27+
y[i] = (Math.pow(t[i], 6)) + (0.3 * normal());
28+
}
29+
30+
var trace1 = {
31+
x: x,
32+
y: y,
33+
mode: 'markers',
34+
name: 'points',
35+
marker: {
36+
color: 'rgb(102,0,0)',
37+
size: 2,
38+
opacity: 0.4
39+
},
40+
type: 'scatter'
41+
};
42+
var trace2 = {
43+
x: x,
44+
y: y,
45+
name: 'density',
46+
ncontours: 20,
47+
colorscale: 'Hot',
48+
reversescale: true,
49+
showscale: false,
50+
type: 'histogram2dcontour'
51+
};
52+
var trace3 = {
53+
x: x,
54+
name: 'x density',
55+
marker: { color: 'rgb(102,0,0)' },
56+
yaxis: 'y2',
57+
type: 'histogram'
58+
};
59+
var trace4 = {
60+
y: y,
61+
name: 'y density',
62+
marker: { color: 'rgb(102,0,0)' },
63+
xaxis: 'x2',
64+
type: 'histogram'
65+
};
66+
const layout = {
67+
showlegend: false,
68+
margin: { t: 50 },
69+
hovermode: 'closest',
70+
bargap: 0,
71+
xaxis: {
72+
domain: [0, 0.85],
73+
showgrid: false,
74+
zeroline: false
75+
},
76+
yaxis: {
77+
domain: [0, 0.85],
78+
showgrid: false,
79+
zeroline: false
80+
},
81+
xaxis2: {
82+
domain: [0.85, 1],
83+
showgrid: false,
84+
zeroline: false
85+
},
86+
yaxis2: {
87+
domain: [0.85, 1],
88+
showgrid: false,
89+
zeroline: false
90+
}
91+
};
92+
93+
export default {
94+
display: "2D Histogram",
95+
data: {
96+
data: [trace1, trace2, trace3, trace4],
97+
attr: {},
98+
layout
99+
}
100+
};

example/components/graphpicker.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import editor from "vue-json-editor";
6868
import simple from "./simple.js";
6969
import contour from "./contour.js";
7070
import histogram from "./histogram.js";
71+
import histogram2D from "./2D-histogram.js"
7172
import pie from "./pie.js";
7273
7374
export default {
@@ -77,7 +78,7 @@ export default {
7778
},
7879
data() {
7980
return {
80-
generics: [simple, contour, histogram, pie],
81+
generics: [simple, contour, histogram, pie, histogram2D],
8182
selected: simple
8283
};
8384
},

0 commit comments

Comments
 (0)