Contour Plots edit page

How to customize contour plots in MTEX

Lets consider an arbitrary spherical function which has no practical meaning at all but serves as a prototype for pole figures, inverse pole figures, Schmidt or Taylor factor maps, etc.

% define the spherical function
plottingConvention.default('y↑→x');
sF = 0.01 + 10*S2Fun.smiley

% and plot it as a smooth function
plot(sF,'upper')
mtexColorMap blue2red
mtexColorbar
sF = S2FunHarmonic (y↑→x)
  bandwidth: 128

Passing the option contour to the plot command we may add contours at specific levels on top of the smooth plot

% enable on top plotting
hold on

% specify the contour levels
levels = -4:5;

% plot the contours
h = plot(sF,'contour',levels,'linewidth',2,'linecolor','k')

% disable on top plotting
hold off
h = 
  Contour with properties:

    EdgeColor: [0 0 0]
    LineStyle: '-'
    LineWidth: 2
    FaceColor: 'none'
    LevelList: [-4 -3 -2 -1 0 1 2 3 4 5]
        XData: [91×361 double]
        YData: [91×361 double]
        ZData: [91×361 double]

  Use GET to show all properties

The plotting command return a handle h to the plotted contours. This handle can be used to customize the contour lines. In particular, one can use the Matlab command clabel to add labels to specific contour levels.

levels2label = [-2,0:5];
clabel(h.ContourMatrix,h,levels2label,'FontSize',15)

A practical example

The situation becomes a little bit more involved if contour lines should be added to multiple plot. Let us consider the pole figures of the following ODF

mtexdata dubna
odf = calcODF(pf,'silent')
pf = PoleFigure (y↑→x)
  crystal symmetry : Quartz (321, X||a*, Y||b, Z||c)
 
  h = (022̅1), r = 72 x 19 points
  h = (101̅0), r = 72 x 19 points
  h = (101̅1)(011̅1), r = 72 x 19 points
  h = (101̅2), r = 72 x 19 points
  h = (112̅0), r = 72 x 19 points
  h = (112̅1), r = 72 x 19 points
  h = (112̅2), r = 72 x 19 points
 
odf = SO3FunRBF (Quartz → y↑→x)
 
  multimodal components
  kernel: de la Vallee Poussin, halfwidth 5°
  center: 19848 orientations, resolution: 5°
  weight: 1

Then we may use the option 'ShowText','on' to display contour labels.

h = pf{4:5}.h;
plotPDF(odf,h)
mtexColorMap LaboTeX
mtexColorbar

hold on
plotPDF(odf,h,'contour',1:2:15,'linecolor','black','linewidth',2,'ShowText','on')
hold off

Citing this page. This page is part of the documentation of MTEX, a free and open source MATLAB toolbox for analyzing and modeling crystallographic textures. It was written by The MTEX Developers and is published at https://mtex-toolbox.github.io/ContourPlots.html. If you use MTEX, or reuse text or figures from this page, in your research, please cite

F. Bachmann, R. Hielscher, H. Schaeben: Texture Analysis with MTEX - Free and Open Source Software Toolbox, Solid State Phenomena 160 (2010), 63-68. 10.4028/www.scientific.net/SSP.160.63

BibTeX
@article{bachmann2010mtex,
  author  = {F. Bachmann and R. Hielscher and H. Schaeben},
  title   = {Texture Analysis with MTEX - Free and Open Source Software Toolbox},
  journal = {Solid State Phenomena},
  volume  = {160},
  pages   = {63-68},
  year    = {2010},
  doi     = {10.4028/www.scientific.net/SSP.160.63},
  url     = {https://doi.org/10.4028/www.scientific.net/SSP.160.63}
}

Other papers describing specific MTEX methods are listed under Publications — please cite the one that best fits your application. The MTEX source code is licensed under the GNU General Public License v2.0; the text and figures of this documentation are licensed under CC BY 4.0, which permits reuse — including by automated systems — provided The MTEX Developers and this page are credited.