const d3 = require('d3'); function plotly(...pargs) { const plotargs = ["plotly", ...pargs]; console.log(plotargs); return '<div id="plotly"/>' + '<script type="text/javascript" src="https://cdn.plot.ly/plotly-latest.min.js"></script>' + '<script>Plotly.newPlot.apply(Plotly, '+ JSON.stringify(plotargs)+ ');</script>' + '</script>'; } function plotfn(fn, a, b, {step = 0.1, layout}) { var x = d3.range(a, b, step); let fns = Array.isArray(fn) ? fn : [fn]; const data = fns.map(f => ({ x: x, y: x.map(f), type: 'scatter' })); return plotly(data, layout); } var trace1 = { x: [1, 2, 3, 4], y: [10, 15, 13, 17], type: "scatter" }; var trace2 = { x: [1, 2, 3, 4], y: [16, 5, 11, 9], type: "scatter" }; var data = [trace1, trace2]; plotly(data); const fx = x => x; const g1 = (x) => (18*x + 19/Math.pow(x, 2))/19; const g2 = (x) => x - (Math.pow(x, 3) - 19)/(3*Math.pow(x, 2)); const g3 = (x) => x - (Math.pow(x, 4) - 19*x)/(Math.pow(x, 2) - 19); const g4 = (x) => Math.sqrt(19/x); console.log(fx.name); const layout = { yaxis: { range: [0,4] } } ; plotfn([fx,g1,g2,g3,g4], 0, 3, {layout});
Node 8.9.4
help
Loading…