To accomplish Python integration with Minitab Statistical Software, Minitab, LLC provides the mtbpy module. The following descriptions of the classes and methods from the mtbpy module prepare you to write Python code that integrates with Minitab Statistical Software.
For information on how to install Minitab's Python module and how to run Python from Minitab Statistical Software, go to Installing Python to use with Minitab Statistical Software.
For more information on Python, consult the guidance available at www.python.org.
The following are the methods for the
mtb_instance
class.
get_column
Retrieves a column from a Minitab worksheet to use in Python.
list
. The
list
can contain either text or numeric values.
from mtbpy import mtbpy
column1 = mtbpy.mtb_instance().get_column("C1")
column2 = mtbpy.mtb_instance().get_column("My Column")
get_constant
Retrieves a constant from a Minitab worksheet to use in Python.
from mtbpy import mtbpy
constant1 = mtbpy.mtb_instance().get_constant("K1")
constant2 = mtbpy.mtb_instance().get_constant("My Constant")
get_matrix
Retrieves a matrix from a Minitab worksheet to use in Python.
list
of
lists
.
from mtbpy import mtbpy
matrix1 = mtbpy.mtb_instance().get_matrix("M1")
matrix2 = mtbpy.mtb_instance().get_matrix("My Matrix")
add_message
Appends a message to the Minitab Output pane.
None
from mtbpy import mtbpy
mtbpy.mtb_instance().add_message("This is a message.")
set_note
Sets a note at the top of the Minitab Output pane.
None
from mtbpy import mtbpy
mtbpy.mtb_instance().set_note("The output contains one note.")
set_note
Sets the title at the top of the Minitab Output pane.
None
from mtbpy import mtbpy
mtbpy.mtb_instance().set_title("The output contains one title.")
add_image
Appends an image to the Minitab Output pane when you have a supported image file.
None
from mtbpy import mtbpy
import numpy as np
import matplotlib.pyplot as plt
N_points = 1000
n_bins = 50
x = np.random.randn(N_points)
y = .4 * x + np.random.randn(N_points) + 5
fig, axs = plt.subplots(1, 2, sharey=True, tight_layout=True)
axs[0].hist(x, bins=n_bins)
axs[1].hist(y, bins=n_bins)
fig.savefig("histogram.png")
mtbpy.mtb_instance().add_image("histogram.png")
add_image_bytes
Appends an image to the Minitab Output pane when you have a bytes object.
None
from mtbpy import mtbpy
image_data = b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\t\x00\x00\x00\t\x08\x02\x00\x00\x00o\xf3\x91G\x00\x00\x00\x01sRGB\x00\xae\xce\x1c\xe9\x00\x00\x00\x04gAMA\x00\x00\xb1\x8f\x0b\xfca\x05\x00\x00\x00\tpHYs\x00\x00\x0e\xc3\x00\x00\x0e\xc3\x01\xc7o\xa8d\x00\x00\x00"IDAT\x18Wc\xd8a\xbb\x8b\x81\x01\'I\xba\x04\x01i\x9c\x12\x04\xa4qJ\x10\x90\xc6)\xb1\xc3v\x17\x00\xfc\x0bE\x08o,\xff\xe2\x00\x00\x00\x00IEND\xaeB`\x82'
mtbpy.mtb_instance().add_image_bytes(image_data)
add_table
Appends a table to the Minitab Output pane.
list
of
lists
.
list
.
""
.
""
.
None
from mtbpy import mtbpy
mytitle = "My table title"
myheaders = ["Header for column 1", "Header for column 2"]
mycolumns = [[1,1,1],[2,2,2]]
myfootnote = "My footnote for the table."
mtbpy.mtb_instance().add_table(columns=mycolumns, headers=myheaders, title=mytitle, footnote=myfootnote)
datetime
format than
Python. To convert from the Minitab
datetime
format to the Unix
datetime
format, use the following code:
from datetime import datetime, timedelta
def minitab_to_unix_datetime(pOrdinal, pEpoch0=datetime(1899, 12, 30)):
return(pEpoch0 + timedelta(days=pOrdinal))