This blog will explain how to create a Stacked Contour Plot if user has data with Cylindrical Coordinates(ro, theta and Z),
It will involve the following steps:
- interpolate data and convert data from cylindrical coordinates to Cartesian coordinates
- Use XYZ gridding to convert xyz data into matrix
- Clip data in matrix with circle.
- Plot stacked colormap surfaces and set them to flat.
- Shift them on Z axis to get stacked contour plots
To follow this blog, please download the attached zip file Cylindrical Coordinates and extract the contents.
Convert from Cylindrical to Cartesian Coordinates
- With a new book active, choose Data: Import From File: Single ASCII and browse to the file z=0.txt. Accept the default settings in the import dialog and click OK. The data file is imported with the Long Name and Units and Comments correctly imported into the column label rows.
- Select the first column, then right-click and choose Set As > Y so all three worksheet columns are designated as Y columns.
- With the first column still selected, go to Analysis: Mathematics: Interpolate/Extrapolate: Open Dialog… Use the settings shown below and click OK.
- Now click on the small green operations lock on the top right of the newly added Col(D) and select Repeat This for All Y Columns from the context menu. This will repeat the same interpolation operation for all your columns.
- Add three new columns to the sheet. Designate them as X, Y and Z and assign Long Names X, Y and Z as well. In the Comments enter Cartesian Coordinates for all three columns.
- Enter the following formulas into the F(X)= cells of the 3 new columns, respectively. This will convert XYZ values into Cartesian coordinates.
- abs(col(D)*cos(col(E)))<0.001? 0:col(D)*cos(col(E))
- abs(col(D)*sin(col(E)))<0.001? 0:col(D)*sin(col(E))
- Col(F)
Convert all data files to Cartesian Coordinates
- With this workbook active, choose Data: Import From File: Multiple ASCII. Select the other txt files from z=20 to z=80 and click Add Files. Make sure Show Options Dialog is checked then click OK.
- In the impASCII dialog that opens, under Import Options, set both 1st File Import Mode and Multi-File (except 1st) Import Mode to Start New Books . Set Template Name to <clone>, which will create new books as needed, putting each new data file into a new book and cloning all operations of the current book. Click OK to close the dialog and clone your input.
- Choose Window: Tile Horizontally, to see that you have one workbook for every z-value dataset:
At this point, If you were to highlight any Z column and choose Plot: 3D : 3D Colormap Surface, then open the Plot Details dialog, check the Flat checkbox on Surface tab, you will see the plot is approximately but not perfectly round. Our goal is to plot each dataset as cross-sections in a perfect cylinder, so we need to perform some additional steps.
Convert XYZ Data to Matrix
-
- Select the Z column (the last column) in the z=0 worksheet and choose Worksheet: Convert to Matrix: XYZ Gridding.
- Expand Gridding Settings and set the Gridding Method and Parameters as Random (Thin Plate Spline).
- Uncheck the box next to Columns and Rows controls and set both as 450.
- Click OK, and this will generate a new matrix.
- With the matrix active, choose View: Show Image Thumbnails. Right-click 1st image icon and use Add to add four more matrix objects to the matrix sheet. These will hold the other XYZ gridding datasets.
- Now select the Z column from z=20 worksheet, press the SHIFT key and and choose Worksheet: Convert to Matrix: XYZ Gridding: <last used>.
- This will open the XYZ Gridding dialog with previous settings loaded. Click the arrow button > to far right of Output Matrix and select Matrix Browser. Set List Matrices to Current Project, then select the second matrix object (Index = 2) in the list. Click Add and then OK out of the dialog.
- Click OK to do the XYZ gridding for the second z=20 dataset. Repeat the above steps for z=40 z=60 and z=80. In the end you should have a matrix book with all the five datasets converted to matrices. You can double click on the text under the thumbnails to edit them and put in the dataset names.
Cut off Data outside the Circle
- As you can see from matrix data and corresponding thumbnails, the matrix has a square shape, not circular. We want to trim the dataset leave just leave data within a circle. To do this, Add 6 more objects to the matrix.
- Click on the sixth thumbnail and press Ctrl+Q to open the Set Values dialog box.
- Put the following equation into the dialog (here, 33000 is the radius): (X^2+Y^2)>33000?0/0:0. This will generate a matrix with a circular shape. All values within circle are 0. All values outside the circle are missing values.
- For 7th matrix, use Ctrl+Q to open the dialog and put in the equation : Mat(1)+Mat(6). This will trim the 1st matrix values so all values outside the circle will be missing values.
- For the remaining matrix objects, use these respective equations to trim:
8> Mat(2)+Mat(6)
9> Mat(3)+Mat(6)
10> Mat(4)+Mat(6)
11> Mat(5)+Mat(6)
Matrix objects from 7 to 11 are those with perfect circle shapes. You can rename these as well. Your matrix should now look like this:
Plot Stacked Contour Plots
- With the 7th matrix active, choose Plot: 3D: 3D Colormap Surface. A 3D plot will be created.
- Double click on the Layer Icon to open the Layer Contents dialog. Now move only the clipped matrices from left to right side of the dialog box..
- This will add all the matrices to one graph and it will look very messy:
- Double click on the plots to open the Plot Details dialog and on the Surface tab, check the Flat checkbox. Check the Shift in Z... checkbox and for each plot set their respective offsets of 0, 20, 40, 60, 80.
- For each plot, you should also disable Mesh on the Mesh tab and disable Contour lines on the Colormap/Contour tab.
- Once you have done this for all the plots, in the Axis dialog you can set the Z scale from 0-100 and add thick black Gridlines on the Z axis.
The end product will now look like this: