Example: Contour Chart from Scattered Data

In this example, a contour chart is created from 150, randomly choosen, scattered data points. The function is \sqrt{x^2+y^2}, so the level curve should be circles.

The input data is shown on top of the contours as small green circles. The chart data nodes are drawn in the order in which they are added, so the input data marker node has to be added to the axis after the contour, so that the markers are not hidden.

using Imsl.Chart2D;
using System;
using System.Windows.Forms;

public class ContourEx2 : FrameChart 
{
	public ContourEx2() 
	{
		Chart chart = this.Chart;

		int n = 150;
		
		// Allocate space
		double[] x = new double[n];
		double[] y = new double[n];
		double[] z = new double[n];
		
		System.Random random = new System.Random((System.Int32) 123457);

		double[] randomValue=new double[150];
		randomValue[0]=0.41312962995625035;
		randomValue[1]=0.8225528716547005;
		randomValue[2]=0.44364905186692527;
		randomValue[3]=0.9887088342522812;
		randomValue[4]=0.9647868112234352;
		randomValue[5]=0.5668831243079411;
		randomValue[6]=0.27386697614898103;
		randomValue[7]=0.8805853693809824;
		randomValue[8]=0.7180829622748057;
		randomValue[9]=0.6153607537410654;
		randomValue[10]=0.3158193853638753;
		randomValue[11]=0.10778543304578747;
		randomValue[12]=0.09275375134615693;
		randomValue[13]=0.9817642781628322;
		randomValue[14]=0.467363186309925;
		randomValue[15]=0.9066980293517674;
		randomValue[16]=0.31440695305815347;
		randomValue[17]=0.9991560762956562;
		randomValue[18]=0.785150345014761;
		randomValue[19]=0.7930129038729785;
		randomValue[20]=0.5695413465811706;
		randomValue[21]=0.7625752595574732;
		randomValue[22]=0.0482465474704169;
		randomValue[23]=0.09904819350827354;
		randomValue[24]=0.7013979421419555;
		randomValue[25]=0.8127581377189425;
		randomValue[26]=0.2160980302718407;
		randomValue[27]=0.2618716012466812;
		randomValue[28]=0.966175212476057;
		randomValue[29]=0.8929180151759015;
		randomValue[30]=0.9253777827882632;
		randomValue[31]=0.3192464623158826;
		randomValue[32]=0.6191390558809441;
		randomValue[33]=0.860615090126798;
		randomValue[34]=0.4202423262221493;
		randomValue[35]=0.3204335652731257;
		randomValue[36]=0.3501592792324697;
		randomValue[37]=0.08674811183862785;
		randomValue[38]=0.5605305915601296;
		randomValue[39]=0.6088802062708134;
		randomValue[40]=0.8382035138841133;
		randomValue[41]=0.9236987545556213;
		randomValue[42]=0.8024356174828979;
		randomValue[43]=0.18382779454152387;
		randomValue[44]=0.9443198089192774;
		randomValue[45]=0.07466011736504485;
		randomValue[46]=0.2961809553169247;
		randomValue[47]=0.597869137157411;
		randomValue[48]=0.3126393883707773;
		randomValue[49]=0.9461805842458413;
		randomValue[50]=0.4952325691501952;
		randomValue[51]=0.0974865497453884;
		randomValue[52]=0.39893060081096055;
		randomValue[53]=0.31595422264648054;
		randomValue[54]=0.9215776190059227;
		randomValue[55]=0.963602405500786;
		randomValue[56]=0.1962353914644036;
		randomValue[57]=0.897888992070645;
		randomValue[58]=0.9816014888911522;
		randomValue[59]=0.2591728892012697;
		randomValue[60]=0.177119526412298;
		randomValue[61]=0.6364841570839579;
		randomValue[62]=0.9770940229311096;
		randomValue[63]=0.44085669522358406;
		randomValue[64]=0.22206796609570068;
		randomValue[65]=0.8125478558454153;
		randomValue[66]=0.7059166517811799;
		randomValue[67]=0.5417895331224579;
		randomValue[68]=0.5535562377071471;
		randomValue[69]=0.2922863750389211;
		randomValue[70]=0.2968612011640126;
		randomValue[71]=0.882495829596943;
		randomValue[72]=0.9453297028667043;
		randomValue[73]=0.5017962685731009;
		randomValue[74]=0.17323198276725293;
		randomValue[75]=0.516968989592425;
		randomValue[76]=0.7264211901923515;
		randomValue[77]=0.9589904164393783;
		randomValue[78]=0.2896822052185578;
		randomValue[79]=0.8709512849886136;
		randomValue[80]=0.3494389711171513;
		randomValue[81]=0.444989615581906;
		randomValue[82]=0.03683604460307233;
		randomValue[83]=0.2794447857758138;
		randomValue[84]=0.5426558540369049;
		randomValue[85]=0.14701055330017276;
		randomValue[86]=0.45822765810918564;
		randomValue[87]=0.3804843649168811;
		randomValue[88]=0.31543075674256227;
		randomValue[89]=0.35478179229078655;
		randomValue[90]=0.6740882045962612;
		randomValue[91]=0.5722042439512296;
		randomValue[92]=0.336494210223919;
		randomValue[93]=0.5425187147067986;
		randomValue[94]=0.6565124760451249;
		randomValue[95]=0.9902292520993252;
		randomValue[96]=0.4546287589180955;
		randomValue[97]=0.9184888233730713;
		randomValue[98]=0.7505359876181693;
		randomValue[99]=0.7124220647583559;
		randomValue[100]=0.3812755838294607;
		randomValue[101]=0.7741986381086996;
		randomValue[102]=0.5856540334323093;
		randomValue[103]=0.1480175568946106;
		randomValue[104]=0.8045988425857213;
		randomValue[105]=0.21523348843743784;
		randomValue[106]=0.2723138761466122;
		randomValue[107]=0.8181756787842892;
		randomValue[108]=0.45453852386561255;
		randomValue[109]=0.10578123947146922;
		randomValue[110]=0.027911361401003143;
		randomValue[111]=0.9849840119600158;
		randomValue[112]=0.8883835561320729;
		randomValue[113]=0.30887148321746527;
		randomValue[114]=0.6268231326584466;
		randomValue[115]=0.8359413755618763;
		randomValue[116]=0.01639605006272593;
		randomValue[117]=0.5543612693431772;
		randomValue[118]=0.3190057747399081;
		randomValue[119]=0.18095345468573598;
		randomValue[120]=0.6370180793354232;
		randomValue[121]=0.5166986319820245;
		randomValue[122]=0.11169309885740164;
		randomValue[123]=0.8688720220933366;
		randomValue[124]=0.5011922442391221;
		randomValue[125]=0.9344952771865647;
		randomValue[126]=0.5587227111699117;
		randomValue[127]=0.3806089260426023;
		randomValue[128]=0.6753272961079825;
		randomValue[129]=0.8539394715414731;
		randomValue[130]=0.4520234874494251;
		randomValue[131]=0.3058558270067878;
		randomValue[132]=0.2224399403890832;
		randomValue[133]=0.3280806679102708;
		randomValue[134]=0.05979465629761105;
		randomValue[135]=0.660441325427476;
		randomValue[136]=0.4710041931991943;
		randomValue[137]=0.15401687157352573;
		randomValue[138]=0.8059082103579294;
		randomValue[139]=0.25135648562180013;
		randomValue[140]=0.3910396401490016;
		randomValue[141]=0.48001615607289505;
		randomValue[142]=0.5350655938328643;
		randomValue[143]=0.5464799882069644;
		randomValue[144]=0.8469694582001581;
		randomValue[145]=0.3646033096669923;
		randomValue[146]=0.7582401994865531;
		randomValue[147]=0.7560344451536601;
		randomValue[148]=0.7467799442143332;
		randomValue[149]=0.619643401693058;

		double[] randomValueY=new double[150];
		randomValueY[0]=0.15995876895053263;
		randomValueY[1]=0.48794367683379836;
		randomValueY[2]=0.20896329070872555;
		randomValueY[3]=0.4781765623804778;
		randomValueY[4]=0.6732389937186418;
		randomValueY[5]=0.33081942994459734;
		randomValueY[6]=0.10880787186704965;
		randomValueY[7]=0.901138442534768;
		randomValueY[8]=0.48723656383264413;
		randomValueY[9]=0.10153552805288812;
		randomValueY[10]=0.9558058275075961;
		randomValueY[11]=0.011829287599608884;
		randomValueY[12]=0.4859902873228249;
		randomValueY[13]=0.5505301300240635;
		randomValueY[14]=0.18652444274911184;
		randomValueY[15]=0.9272326533193322;
		randomValueY[16]=0.4215880116306273;
		randomValueY[17]=0.0386317648903991;
		randomValueY[18]=0.6451521871931544;
		randomValueY[19]=0.819301055474355;
		randomValueY[20]=0.039285689951912395;
		randomValueY[21]=0.31325564481720314;
		randomValueY[22]=0.6272275622766595;
		randomValueY[23]=0.8934533907186641;
		randomValueY[24]=0.5212913217641422;
		randomValueY[25]=0.6237725863035143;
		randomValueY[26]=0.3611731793838059;
		randomValueY[27]=0.23163547542978535;
		randomValueY[28]=0.7999943624102621;
		randomValueY[29]=0.5393314259940907;
		randomValueY[30]=0.10341603798162413;
		randomValueY[31]=0.48822476962455685;
		randomValueY[32]=0.5414223626279245;
		randomValueY[33]=0.08241640235000847;
		randomValueY[34]=0.27287579633296155;
		randomValueY[35]=0.6770605504344167;
		randomValueY[36]=0.8497059767892107;
		randomValueY[37]=0.04142051621448373;
		randomValueY[38]=0.30060172837976995;
		randomValueY[39]=0.5378809821731352;
		randomValueY[40]=0.9933333184285308;
		randomValueY[41]=0.5755163489718148;
		randomValueY[42]=0.12033991348116369;
		randomValueY[43]=0.22044795260992822;
		randomValueY[44]=0.7039752563092764;
		randomValueY[45]=0.47510550779825345;
		randomValueY[46]=0.47581191139276346;
		randomValueY[47]=0.2746412789430772;
		randomValueY[48]=0.8486627562667742;
		randomValueY[49]=0.6911278265254134;
		randomValueY[50]=0.47048601468635676;
		randomValueY[51]=0.18480344365963364;
		randomValueY[52]=0.5260974820985063;
		randomValueY[53]=0.9965118715946334;
		randomValueY[54]=0.03562254706322543;
		randomValueY[55]=0.9366159496862719;
		randomValueY[56]=0.8878769321024975;
		randomValueY[57]=0.8930475165444577;
		randomValueY[58]=0.24237426250726957;
		randomValueY[59]=0.354788700886031;
		randomValueY[60]=0.2354154511947073;
		randomValueY[61]=0.1269624995880959;
		randomValueY[62]=0.6337231423679252;
		randomValueY[63]=0.19984371337284335;
		randomValueY[64]=0.19334220894181153;
		randomValueY[65]=0.42648351165619114;
		randomValueY[66]=0.0020349209904862997;
		randomValueY[67]=0.26227419862014245;
		randomValueY[68]=0.010157565396595736;
		randomValueY[69]=0.32466354319724255;
		randomValueY[70]=0.2880125699286028;
		randomValueY[71]=0.942360375989513;
		randomValueY[72]=0.28692884801712293;
		randomValueY[73]=0.18075667041036092;
		randomValueY[74]=0.526829825487406;
		randomValueY[75]=0.05392345053644676;
		randomValueY[76]=0.6848072074260566;
		randomValueY[77]=0.7634213162987096;
		randomValueY[78]=0.017226310006998813;
		randomValueY[79]=0.8402985996291047;
		randomValueY[80]=0.41214609100356114;
		randomValueY[81]=0.00903342798862894;
		randomValueY[82]=0.13934521987605275;
		randomValueY[83]=0.44080857560050446;
		randomValueY[84]=0.5420034416544178;
		randomValueY[85]=0.8183907621649894;
		randomValueY[86]=0.49709491461841304;
		randomValueY[87]=0.2960190585426765;
		randomValueY[88]=0.4608082576003252;
		randomValueY[89]=0.005089578506740633;
		randomValueY[90]=0.3108158643301907;
		randomValueY[91]=0.23005689707662969;
		randomValueY[92]=0.9989728680293828;
		randomValueY[93]=0.7588548659179764;
		randomValueY[94]=0.23603371611553747;
		randomValueY[95]=0.1982727511862804;
		randomValueY[96]=0.04423243217165507;
		randomValueY[97]=0.23710549829602878;
		randomValueY[98]=0.03408034658051773;
		randomValueY[99]=0.9385290439821878;
		randomValueY[100]=0.6884926962578499;
		randomValueY[101]=0.14803546698365633;
		randomValueY[102]=0.7703636833850115;
		randomValueY[103]=0.01439471413150828;
		randomValueY[104]=0.2089671359503994;
		randomValueY[105]=0.4384925493939328;
		randomValueY[106]=0.466067663723164;
		randomValueY[107]=0.9885280557996187;
		randomValueY[108]=0.4343852116079696;
		randomValueY[109]=0.4499354044927121;
		randomValueY[110]=0.3790637460316687;
		randomValueY[111]=0.7145286684532488;
		randomValueY[112]=0.2970523498826292;
		randomValueY[113]=0.15575074519991794;
		randomValueY[114]=0.33981500752026883;
		randomValueY[115]=0.9855399747339232;
		randomValueY[116]=0.621543401362443;
		randomValueY[117]=0.3432116007462742;
		randomValueY[118]=0.8180541618673799;
		randomValueY[119]=0.027883366004455068;
		randomValueY[120]=0.45081070184878236;
		randomValueY[121]=0.8533577155496994;
		randomValueY[122]=0.6460168649513455;
		randomValueY[123]=0.5780055157336823;
		randomValueY[124]=0.46048777917596295;
		randomValueY[125]=0.24207983525545718;
		randomValueY[126]=0.574011233178295;
		randomValueY[127]=0.5310197638599929;
		randomValueY[128]=0.2621701535374652;
		randomValueY[129]=0.4756887402397726;
		randomValueY[130]=0.08410532225672551;
		randomValueY[131]=0.3991230601447665;
		randomValueY[132]=0.6464545787001537;
		randomValueY[133]=0.524250367439074;
		randomValueY[134]=0.13771323020945658;
		randomValueY[135]=0.06816969003124507;
		randomValueY[136]=0.06651758347488423;
		randomValueY[137]=0.965968335289986;
		randomValueY[138]=0.7828616693306287;
		randomValueY[139]=0.5906828761391884;
		randomValueY[140]=0.9130151004091689;
		randomValueY[141]=0.9658950710812012;
		randomValueY[142]=0.7969176634278117;
		randomValueY[143]=0.003585724779986199;
		randomValueY[144]=0.38108388460809595;
		randomValueY[145]=0.24225280334829336;
		randomValueY[146]=0.7905591927051523;
		randomValueY[147]=0.4089325882708409;
		randomValueY[148]=0.9802263978904657;
		randomValueY[149]=0.8836456558655017;

		for (int k = 0; k < n; k++)
		{
			x[k] = randomValue[k];
			y[k] = randomValueY[k];
			z[k] = System.Math.Sqrt(x[k] * x[k] + y[k] * y[k]);
		}
		
		// Setup the contour plot and its legend
		AxisXY axis = new AxisXY(chart);
		Contour contour = new Contour(axis, x, y, z);
		contour.ContourLegend.IsVisible = true;
		
		// Show the input data points as small green circles
		Data dataPoints = new Data(axis, x, y);
		dataPoints.DataType = Data.DATA_TYPE_MARKER;
		dataPoints.MarkerType = Data.MARKER_TYPE_FILLED_CIRCLE;
		dataPoints.MarkerColor = System.Drawing.Color.FromArgb(0, 255, 0);
		dataPoints.MarkerSize = 0.5;	
	}

	public static void Main(string[] argv) 
	{
		System.Windows.Forms.Application.Run(new ContourEx2());
	}
}

Output

Link to C# source.