IMSL C# Programmer’s Guide
Charting 2D Types >> Contour Chart  Previous Page  Contents  Next Page

Contour Chart

A Contour chart shows level curves of a two-dimensional function.

Example

The FrameChart class is used to create a frame containing a Chart node. A Contour node is then created as a child of the Chart node. The Contour node constructor creates ContourLevel nodes as its children. The number of ContourLevel nodes created is equal to the number of contour levels plue one, here equal to 4.  After the ContourLevel nodes are created they are retrieved from the object pie and customized by setting attributes.

The FillColor and LineColor attributes are set in each level. This determines the color of the fill area for the level and the color of the level curves. Since the default value of FillColor is black, it is generally recommended that FillColor be set in each level.

Each level corresponds to the area less than or equal to the contour level value and greater than the previous level, if any. So in this example, since the 0-th level value is 0.4, the area where the function is less than 0.4 is filled with blue (the level-0 fill color) and the level curve equal to 0.4 is draw with dark blue, the level-0 line color.

(Download Code)
using Imsl.Chart2D;
using System;
using System.Drawing;

public class SampleContour : FrameChart {

    public SampleContour() {
        Chart chart = this.Chart;
        AxisXY axis = new AxisXY(chart);

        double[] xGrid = {0, 0.2, 0.4, 0.6, 0.8, 1.0};
        double[] yGrid = {0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 1.0};
        double[,] zData = new double[xGrid.Length, yGrid.Length];
        for (int i = 0;  i < xGrid.Length;  i++) {
            for (int j = 0;  j < yGrid.Length;  j++) {
                double x = xGrid[i];
                double y = yGrid[j];
                zData[i,j] = Math.Exp(-x) * Math.Cos(x-y);
            }
        }
        double[] level = {0.4, 0.6, 0.8};
        Contour contour = new Contour(axis, xGrid, yGrid, zData, level);
        contour.ContourLegend.IsVisible = true;
        contour.GetContourLevel(0).FillColor = Color.Blue;
        contour.GetContourLevel(1).FillColor = Color.Yellow;
        contour.GetContourLevel(2).FillColor = Color.Green;
        contour.GetContourLevel(3).FillColor = Color.Red;

        contour.GetContourLevel(0).LineColor = Color.DarkBlue;
        contour.GetContourLevel(1).LineColor = Color.Orange;
        contour.GetContourLevel(2).LineColor = Color.DarkGreen;
        contour.GetContourLevel(3).LineColor = Color.DarkRed;
    }

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



©  Visual Numerics, Inc.  All rights reserved.  Previous Page  Contents  Next Page