algorithm - Generating random data for a scatter plot -
i'm testing out different javascript graphing frameworks. i'm trying out line graphs , scatter plots generated data. while it's going quite okay. i've run trouble while trying generate data scatter plot.
so quite easy in php, or in other language:
for ($i=0; $i < $x; $i++) { $data[] = array( 'x' => mt_rand(0, 10000), 'y' => mt_rand(0, 10000) ); }
the result distributed pretty equally around whole chart. here trying think of way come better random data, more scatter plot, rather equally distributed dots on page. , can't come anything.
i end more random scatter plot web:
so more intense in part of plot , pretty nothing in corners. wouldn't make impossible dot make corners.
any algorithmic ideas?
for image showed, have line around want scatter data, it's pretty easy. example, imagine line in y = x * 0.75
. given that, select x
value in range 0..xmax
(whatever maximum x value is), , generate value y
variance. example, if 90% of time y value within 10% of expected value, you'd generate random value between 0.675x , 0.825x.
say 5% of time, y value within 50% of expected value , 5% of time value unconstrained. each of those, generate y value same way: random value equal expected y value, plus or minus 50% (or, in latter case, plus or minus large number).
you can adjust probabilities , variance appropriate.
you can adjust distribution of x values. example, looks of data points between .15 xmax , .6 xmax. want higher percentage of x values in range. imagine, x values broken 3 different ranges:
0 .149 * xmax - 20% .15 .60 * xmax - 70% > .60 xmax - 10%
generate random number between 0 , 100. then:
if value < 20, generate x value between 0 , .15 xmax if value > 19 & < 60, generate x value between .15 xmax , .60 xmax otherwise, generate x value > .60 xmax , < xmax
Comments
Post a Comment