excel surface plots contours

5
Home | Archives | Authors | About Us | Subscribe/Membership | Consultants | Mouse Droppings | Feedback | Member Login Issue | Department | Next Article | Previous Article Surface and Contour Charts in Microsoft Excel by Jon Peltier, MVP Introduction Surface charts are the only useful and valid 3D chart types offered by Excel. They have three true dimensions in the data, and can illustrate it reasonable well. Surface charts are useful to show how a variable (Z) changes according to two other variables (X and Y). For example, a topographic map shows how altitude (Z) changes with longitude and lattitude (X and Y). Surface charts have some limitations: Surface charts are not true X-Y-Z charts. X and Y are not treated as numeric data, and must consist of regularly defined, evenly spaced categories. Exactly one Z value is needed for each X-Y pair. The surface calculations are rudimentary, drawn by connecting Z values at X-Y nodes with straight lines and planar sections. A saddle point is not accurately drawn if it occurs between the X-Y nodes. The color-filled surface charts do not allow transparency, which would help visualize hidden parts of the surface. (Perhaps Excel for the Mac allows this, but that's insufficient cause to trade in your Windows machine for a Mac.) The wireframe versions of the surface chart have too many visible line segments, showing both the boundaries marking different values and the lines connecting the nodes. They can only be hidden and displayed together; whereas it would have been a nice feature to show boundaries only, or formatted differently from node connectors. Despite these and other limitations, surface charts and contour charts, their 2D equivalents, can be quite effective in presenting information. Data Considerations for Surface Charts 3D Charts in Excel Of the many 3D chart types offered by Excel, the only useful ones are Surface charts. Most 3D charts offered by Excel are two dimensional in the data, and have a false third dimension. They portray the data as if the chart were drawn on a board and cut out, so the elements have an arbitrary thickness, then viewed at an oblique angle. This has the effect of making the charts difficult to read, because it's hard for the viewer to extrapolate through an imaginary space to the axes. If the Perspective property of the 3D view is set to anything but zero, the ability to compare the relative heights of adjacent chart elements is also lost. In 99% of the cases, I recommend that people convert their fancy 3D charts into the equivalent 2D chart types. In addition to potential distortion of the data, 3D charts are less functional than 2D charts. The false third dimension takes up space in the chart, forcing the actual data into a smaller area. If you use a 3D chart, you also give up useful chart features, such as error bars, data labels, and the ability to combine different chart types in the same chart. Page 1 of 5 Surface and Contour Charts in Microsoft Excel 5/1/2012 http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=447

Upload: raj-rajendran

Post on 21-Apr-2015

64 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Excel Surface Plots Contours

Home | Archives | Authors | About Us | Subscribe/Membership | Consultants | Mouse Droppings | Feedback | Member LoginIssue | Department | Next Article | Previous Article

Surface and Contour Charts in Microsoft Excel

by Jon Peltier, MVPIntroduction

Surface charts are the only useful and valid 3D chart types offered by Excel. They have three true dimensions in the data, and can illustrate it reasonable well. Surface charts are useful to show how a variable (Z) changes according to two other variables (X and Y). For example, a topographic map shows how altitude (Z) changes with longitude and lattitude (X and Y).

Surface charts have some limitations:

Surface charts are not true X-Y-Z charts. X and Y are not treated as numeric data, and must consist of regularly defined, evenly spaced categories. Exactly one Z value is needed for each X-Y pair.

The surface calculations are rudimentary, drawn by connecting Z values at X-Y nodes with straight lines and planar sections. A saddle point is not accurately drawn if it occurs between the X-Y nodes.

The color-filled surface charts do not allow transparency, which would help visualize hidden parts of the surface. (Perhaps Excel for the Mac allows this, but that's insufficient cause to trade in your Windows machine for a Mac.)

The wireframe versions of the surface chart have too many visible line segments, showing both the boundaries marking different values and the lines connecting the nodes. They can only be hidden and displayed together; whereas it would have been a nice feature to show boundaries only, or formatted differently from node connectors.

Despite these and other limitations, surface charts and contour charts, their 2D equivalents, can be quite effective in presenting information.

Data Considerations for Surface Charts

3D Charts in ExcelOf the many 3D chart types offered by Excel, the only useful ones are Surface charts. Most 3D charts offered by Excel are two dimensional in the data, and have a false third dimension. They portray the data as if the chart were drawn on a board and cut out, so the elements have an arbitrary thickness, then viewed at an oblique angle. This has the effect of making the charts difficult to read, because it's hard for the viewer to extrapolate through an imaginary space to the axes. If the Perspective property of the 3D view is set to anything but zero, the ability to compare the relative heights of adjacent chart elements is also lost. In 99% of the cases, I recommend that people convert their fancy 3D charts into the equivalent 2D chart types. In addition to potential distortion of the data, 3D charts are less functional than 2D charts. The false third dimension takes up space in the chart, forcing the actual data into a smaller area. If you use a 3D chart, you also give up useful chart features, such as error bars, data labels, and the ability to combine different chart types in the same chart.

Page 1 of 5Surface and Contour Charts in Microsoft Excel

5/1/2012http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=447

Page 2: Excel Surface Plots Contours

As described under limitations above, a surface chart's X and Y data are not treated as numeric values, and must consist of regularly defined, evenly spaced categories. Exactly one Z value is needed for each X-Y pair. Your data should be arranged in a grid, with X values or labels in the top row, Y values or labels in the left column, and the Z values arrayed in the resulting grid. The top left cell should be blank. This shows the appropriate data structure:

Convert data list to data table

What if you have a list of data, with three columns for the X, Y, and Z data, as shown:

The easiest and fastest way to rearrange your list into a surface-chart-ready table is with a pivot table. Select the list, and from Excel's Data menu, choose Pivot Table Report. When the empty frame of the pivot table appears (or in the Layout tab of the wizard, if you're still using Excel 97), drag the X field to the Columns area, the Y field to the Rows area, and the Z field to the Data area. The resulting pivot table looks like this:

If there is any blank cell in the pivot table, you should put a value into it. Since you can't change the pivot table directly, you need to insert a row in the source data table that will produce an appropriate value in the calculated table, then refresh the pivot table. Through the Tools menu, Options submenu, Chart tab, Excel offers an option to ignore blanks (leave a gap) in a chart, or to interpolate across a blank. The option to ignore blanks is disabled for a surface chart, and the interpolate option does not prevent the blank from being plotted as a zero. This usually appears as an undesired spike within the chart.

You can make this pivot table directly into a pivot chart. At first, Excel makes a column chart, but you can use Chart Type on the Chart menu to select a Surface or other chart type. When making the pivot chart, Excel ignores the grand total row and column and all the labels besides the X and Y labels.

You can also make a regular surface chart from the data, but it's not easy to prevent Excel form changing the chart to a pivot chart. An easy and reliable way to produce a regular chart is to copy the pivot table, then use Paste Special - Link to paste the data in another range. Delete the grand total row and column and all the labels other than the X and Y labels before continuing.

For more information about pivot tables, check the pivot table pages and links on my web site, contributed by Debra Dalgleish.

Creating a Surface Chart

X1 X2 X3Y1 Z11 Z12 Z13Y2 Z21 Z22 Z23Y3 Z31 Z32 Z33

X Y ZA a 3B a 2C a 1A b 2B b 2C b 2A c 1B c 2C c 3

Sum of Z XY A B C Grand Totala 3 2 1 6b 2 2 2 6c 1 2 3 6Grand Total 6 6 6 18

Page 2 of 5Surface and Contour Charts in Microsoft Excel

5/1/2012http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=447

Page 3: Excel Surface Plots Contours

I decided to use some saddle point data to illustrate surface charts, since it provides a good illustration of the capabilities of a surface chart. I learned from this web page, Extrema of a function and saddle points, that a saddle point is defined by this formula:

Z = X2 - Y2

I made a table to compute the Z values as follows. I put X values between -2 and 2 in cells B1:J1, and Y values between -2 and 2 in cells A2:A10. I selected B2:J10, with B2 as the active cell, and entered this formula into the formula bar:

=B$1^2-$A2^2

and held CTRL while pressing Enter, to enter the formula into the entire selected range.

To create the chart, select the data range, and press the Chart Wizard button on Excel's Standard Toolbar, or from the Insert Menu, choose Chart... In Step 1 of the wizard, choose the Surface chart type, and select one of the Surface chart subtypes:

3-D Surface Wireframe 3-D Surface Contour Wireframe Contour

The Surface and Contour charts have regions that are colored according to Z value. The Contour chart is a 2D top view of the 3D Surface chart. The wireframe versions of the charts show the lines but not colored fills. The saddle point data looks like this using these four surface chart subtypes:

-2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0-2.0 0.00 -1.75 -3.00 -3.75 -4.00 -3.75 -3.00 -1.75 0.00-1.5 1.75 0.00 -1.25 -2.00 -2.25 -2.00 -1.25 0.00 1.75-1.0 3.00 1.25 0.00 -0.75 -1.00 -0.75 0.00 1.25 3.00-0.5 3.75 2.00 0.75 0.00 -0.25 0.00 0.75 2.00 3.750.0 4.00 2.25 1.00 0.25 0.00 0.25 1.00 2.25 4.000.5 3.75 2.00 0.75 0.00 -0.25 0.00 0.75 2.00 3.751.0 3.00 1.25 0.00 -0.75 -1.00 -0.75 0.00 1.25 3.001.5 1.75 0.00 -1.25 -2.00 -2.25 -2.00 -1.25 0.00 1.752.0 0.00 -1.75 -3.00 -3.75 -4.00 -3.75 -3.00 -1.75 0.00

Surface Chart Surface Wireframe Chart

Page 3 of 5Surface and Contour Charts in Microsoft Excel

5/1/2012http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=447

Page 4: Excel Surface Plots Contours

The four charts show the data to a various degree of success. The colored surface chart and the colored contour chart do it best, with the surface chart probably giving a better sense of the changing Z values. The wireframe surface chart is not as easy to interpret as the filled one. The ability to use a lighter shade of gray for hidden lines would help this, but we aren't offered this option. The wireframe contour chart isn't much use at all. You would have to add a lot of textboxes to identify the lines of equal Z value.

Formatting Surface Charts

Some of our favorite formatting tricks are not available in surface charts. Surface charts do not support data labels, error bars, secondary axes, or combinations with series of other chart types. The X and Y axes are almost untouchable: you can choose whether to show tick labels, and how frequently, and you can format the text. Because these axes are category type axes, you can't change the scales. There is no time axis option.

You can format the colors of all of the surface chart elements. You can add chart and axis titles through the chart wizard or through Chart Options on the Chart menu. These are formatted by double clicking. Chart Options also provides for gridlines and the legend. The line styles of the gridlines and axes can be formatted by double clicking. The floor and walls of the chart can also be formatted by double clicking; the floor can have distinct patterns, but the walls have the same formats.

Double-clicking on the Z axis or on the legend allows you to format the axis scale. Changing the scale also changes the number of ranges of data displayed in the legend: Each major scale division on the axis has a distinct legend entry. The only way to format the colors of a range of data in a surface chart is through the legend. It takes one click to select the legend, a second to select the small colored square, and then a double click to access the Format Legend Key dialog (this is a good time to use CTRL-1). This is one way to format a series in a more conventional chart, but it's the only way to format the data colors in a surface chart.

The sample charts in this article have been formatted with a uniform pattern of colors. It's not exactly the ROY G BIV color scheme in a rainbow (Red-Orange-Yellow Green Blue-Indigo-Violet), but it moves from blue for low values up to red and purple for high values. This convention is similar to that used in high powered computational modeling packages. It works for them and it works for me.

Formatting the color of the legend key specifies the color associated with data within that band. Formatting the border of the legend key determines the line formatting for the lines between the data bands and the lines within the bands corresponding to gridlines on the chart floor. These two sets of lines cannot be formatted independently. In some cases you can reduce the cluttered appearance of the chart without reducing its clarity. This effect works better with contour charts (below right) than

Contour Chart Contour Wireframe Chart

Formatting in ExcelThere are several ways to access the format dialog for an object in Excel. The conventional way is to double click on the object, and this article refers often to double clicking. Another way to open the formatting dialog is to select the object, and choose the top menu item on the Format menu. The name of this menu item changes to reflect the selected object: Format Cells, Format Selected Series, Format Selected Chart Area, etc. My favorite shortcut is to select the object, then press CTRL+1, that is, hold the CTRL key while pressing the "one" key (the one above the Q key, not the one on the numeric keypad). This applies to any object in Excel, not just chart elements.

Page 4 of 5Surface and Contour Charts in Microsoft Excel

5/1/2012http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=447

Page 5: Excel Surface Plots Contours

with surface charts (below left).

Another effective way to reduce clutter in a surface chart is to hide everything but the data. Format the walls, floor, and axes to have no line, no border, and no fill, and delete the legend. This is shown for both the standard and wireframe surface charts below. The 3D view setting was also adjusted slightly in these two charts.

Alternatives to Excel Surface Charts

As noted throughout this article, there are substantial deficiencies in Excel's implementation of surface and contour charts. Excel does not have a 3D XYZ Scatter charting capability. Excel MVP Andy Pope has a simulated 3D scatter chart example, which makes use of worksheet trignometry formulas (http://andypope.info/charts.htm).

If you need a more rigorous 3D scatter, surface, or contour charts, you need to investigate one of the third party add-ins and programs available on the market. I have no experience with any of these; Excel MVP Tushar Mehta has posted a short list of candidates in the Microsoft Excel newsgroups, at http://www.google.com/groups?selm=MPG.1710f373ed45532a98a5ad%40msnews.microsoft.com. You could search on Google for more alternatives.

Surface Chart Contour Chart

Surface Chart Surface Wireframe Chart

Copyright (c) 2002–2012 by MouseTrax Computing Solutions, www.mousetrax.com, Chicago, IL, All Content is Copyrighted and All Rights Reserved

This site powered by the Logical Web Publisher™: Content management by Logical Expressions, Inc.

Page 5 of 5Surface and Contour Charts in Microsoft Excel

5/1/2012http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=447