MTEX for Python
MTEX is the toolbox for crystallographic texture analysis. This package is MTEX in Python, with the names, the syntax and the numbers of the MATLAB toolbox:
- crystal geometry: point groups, crystal frames, Miller indices, orientations and misorientations
- EBSD maps: import from every major vendor format, grains, boundaries, intragranular quantities, denoising, parent grain reconstruction, maps of volumes
- pole figures: import, and ODF reconstruction from them
- functions on the sphere and on the orientation space: density estimation, harmonic expansions, texture characteristics
- tensors: elasticity, plasticity, the Taylor model, optics
- publication ready plots: pole figures, inverse pole figures, ODF sections, maps, 3D scenes
Installation
pip install "mtex[all]"
The plain pip install mtex needs NumPy, SciPy and finufft only. The extras add the rest:
numba compiled kernels (much faster, strongly recommended), plot matplotlib, io the HDF5
formats, plot3d PyVista for the 3D scenes, wizard the import window; all is all of them.
MTEX runs on Python 3.12 or later on Linux, macOS and Windows.
A first look
from mtex import *
# an EBSD map of forsterite, enstatite and diopside
ebsd = mtexdata('forsterite')
# grains by a 10 degree threshold
grains = calcGrains(ebsd['indexed'], angle=10 * degree, minPixel=5)
# the orientation density of forsterite and its pole figures
ori = ebsd['Forsterite'].orientations
odf = calcDensity(ori, halfwidth=10 * degree)
plotPF(odf, Miller([[1, 0, 0], [0, 1, 0], [0, 0, 1]], ori.CS))
mtexdata downloads the sample data sets on first use from
mtex-toolbox/mtex-data.
Working as in MATLAB: VS Code
MATLAB is one program; in Python the editor is separate. VS Code with two extensions plays the part of the MATLAB desktop:
- Install VS Code and, from its Extensions panel (Ctrl+Shift+X), the Python and the Jupyter extensions published by Microsoft.
- Open your project folder (File > Open Folder...), press Ctrl+Shift+P, choose
Python: Create Environment, then Venv and a Python 3.12 or later. This makes a folder
.venv, the counterpart of MTEX on the MATLAB path, but per project. - In Terminal > New Terminal (its prompt starts with
(.venv)) typepip install "mtex[all]" ipykernel.
Then the pieces of the MATLAB desktop are:
| MATLAB | VS Code |
|---|---|
a section %% in the editor |
a cell # %% in a .py file; Shift+Enter runs it and moves on, Ctrl+Enter runs it again |
| the command window | the input box at the bottom of the Interactive window (Shift+Enter runs), or Ctrl+Shift+P, Jupyter: Create Interactive Window |
| the workspace | Variables in the toolbar of the interactive window |
clear all |
Restart in the toolbar of the interactive window |
| figure windows | figures inline in the interactive window; run %matplotlib qt once for separate windows that zoom and turn |
# %%
from mtex import *
# %%
ebsd = mtexdata('forsterite')
ebsd
# %%
plot(ebsd)
The first time, VS Code asks for a kernel: choose the one named .venv. The page
Installing MTEX for Python goes through
every step for Windows, macOS and Linux, with conda and uv as alternatives and what to do when
something goes wrong.
Documentation
The documentation is the MTEX documentation,
every page in MATLAB and in Python, switched by the MATLAB | Python button at the top of a
page; the Python version of a page is <Page>_py.html. Coming from MATLAB, read
MTEX in MATLAB and in Python first. The
rules are few: a flag is a keyword ('antipodal' becomes antipodal=True), indexing takes
brackets (ebsd('indexed') becomes ebsd['indexed']), and a method is called with
parentheses (rot.angle()). help(calcGrains), or hovering over a name in VS Code, shows the
help of a function.
Every page is a script, and the pages come with the package, so they also work offline:
openDoc() # every page, by chapter
openDoc('Tutorials') # the pages of one chapter
openDoc('EBSDTutorial') # the page as EBSDTutorial.py, opened in VS Code
openDoc('EBSDTutorial', notebook=True) # the page as the Jupyter notebook EBSDTutorial.ipynb
The script has a # %% cell for every section, the text of the page as # %% [markdown]
cells; run it with Shift+Enter cell by cell and the interactive window rebuilds the page. The
notebook opens in VS Code, JupyterLab or Jupyter Notebook with the results below each cell.
The file is written into the current folder (or folder=) and never overwritten, so your
changes are safe; overwrite=True brings back the original. The name of a page is the last
part of its web address: .../EBSDTutorial_py.html is EBSDTutorial. Every page on the
website also has a download as script link.
The import wizard
The import wizard opens EBSD files in a window, shows the phases, the reference frame and the
map, and writes the Python script that imports them (it needs the wizard extra, which
mtex[all] includes). Start it from Python
importWizard() # browse the current folder
importWizard('data/ebsd') # a folder, or a file to open at once
ebsd = importWizard() # the map it imported, when the window is closed
or from a terminal with the environment active: mtex-wizard [folder or file], or
python -m mtex.wizard. See EBSD Import.
Settings
A preference holds for the session; save=True keeps it for every later one, stored in
mtex_settings.json in your configuration folder (~/.config/mtex on Linux and macOS,
%APPDATA%\mtex on Windows), MATLAB's mtex_settings.m:
plottingConvention.default('y↑→x', save=True) # maps and pole figures drawn with y up
setMTEXpref('displayRows', 40, save=True) # rows a long array shows
settingsFile() # where the file is
A fresh installation has no file and draws with y down (y↓→x). The environment variable
MTEX_SETTINGS names another file, or with an empty value switches the file off.
Licence
MTEX is free software under the GNU General Public License, version 2; see LICENSE.
The MATLAB toolbox is at mtex-toolbox/mtex.
Metadata
Release files for mtex 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mtex-1.0.0.tar.gz | 3.6 MB | With provenance | Details for mtex-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mtex-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for mtex-1.0.0-py3-none-any.whl |
Total release size: 5.7 MB
Release files / mtex-1.0.0.tar.gz
| Download URL | mtex-1.0.0.tar.gz |
|---|---|
| Size | 3.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3f4d332fea91dabaaaa7b71e0696609904b8295d6e484ae11ff2238e240cab77
|
|
BLAKE2b-256 checksum How to use checksums |
ec70a1ac9eb654c7104c04cb39e70496cf4728b566b6fe1bd1371a85b925a984
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.
Transparency logRelease files / mtex-1.0.0-py3-none-any.whl
| Download URL | mtex-1.0.0-py3-none-any.whl |
|---|---|
| Size | 2.1 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
25acfeb9a2de2460d76bc2a84705a51fd4fed070d3340cf50fbebdd38f370d59
|
|
BLAKE2b-256 checksum How to use checksums |
09fcc347fe710a3bc70aa7fae818b588781d79de887c859297db44edc69fdad1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.
Transparency logSecurity for mtex 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mtex-1.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.