// Numbas version: exam_results_page_options {"name": "Draw a 3d plot with vis.js", "extensions": ["visjs", "stats"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"variables": {"data": {"description": "

Some interesting-looking data: sum a few 2D normal distributions with different centres.

", "group": "Ungrouped variables", "definition": "gatherpoints(listsum(map(sample_peak(c[0],c[1],c[2],c[3]),c,centres)))", "templateType": "anything", "name": "data"}, "centres": {"description": "", "group": "Ungrouped variables", "definition": "repeat(let(d,random(2..4),[random(-5..5),d,random(-5..5),d]),3)", "templateType": "anything", "name": "centres"}}, "showQuestionGroupNames": false, "functions": {"listsum": {"parameters": [["lists", "list"]], "language": "jme", "definition": "if(len(lists)>0,lists[0]+listsum(lists[1..len(lists)]),[])", "type": "number"}, "sample_peak": {"parameters": [["x_mean", "number"], ["x_sd", "number"], ["y_mean", "number"], ["y_sd", "number"]], "language": "jme", "definition": "// generate a load of samples from a 2D normal distribution\nrepeat(\n [round(normalsample(x_mean,x_sd)),round(normalsample(y_mean,y_sd))],\n 10000\n )", "type": "number"}, "gatherpoints": {"parameters": [["data", "list"]], "language": "javascript", "definition": "// count the number of points at each coordinate\n// takes a list of [x,y] coordinates representing points\n// returns a list of data of the form [x,y,count]\n\ndata = data.sort(function(a,b){return a[0]b[0] ? 1 : a[1]b[1] ? 1 : 0});\nvar out = [];\nfor(var i=0;iA plot of a function\n

\\[ \\simplify{sin(x/50)*cos(x/50)*50+50} \\]

\n

{plot3dfunction(sin(x/50) * cos(y/50) * 50 + 50,x,0..300#6,y,0..300#6)}

\n

Some random data

\n

{plot3dpoints(data)}

\n

Boxes instead of a surface

\n
Boxes go here
", "ungrouped_variables": ["data", "centres"], "tags": [], "parts": [], "rulesets": {}, "preamble": {"js": "question.onHTMLAttached(function() {\n var expr = Numbas.jme.compile('x*x-y*y');\n var xvals = (new Numbas.jme.types.range([-5,5,1])).value.slice(3);\n var yvals = (new Numbas.jme.types.range([-5,5,1])).value.slice(3);\n var options = {\n verticalRatio: 0.5,\n style: 'bar-size'\n }\n var graph = Numbas.extensions.visjs.plot3dfunction(expr,question.scope,'x',xvals,'y',yvals,options);\n $(question.display.html).find('#boxes').html(graph.containerElement);\n})", "css": ""}, "name": "Draw a 3d plot with vis.js", "variable_groups": [], "question_groups": [{"pickingStrategy": "all-ordered", "pickQuestions": 0, "questions": [], "name": ""}], "metadata": {"licence": "Creative Commons Attribution 4.0 International", "description": "

This question uses the vis.js library to plot 3D functions and data sets.

\n

As well as JME functions to make plots, you can use javascript functions to get more control over how the plots are rendered.

", "notes": ""}, "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}]}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}