If you’ve ever wished for an easy way to add a custom analysis to Minitab’s interface, read on! Minitab’s new Python integration feature allows an avenue for easily running custom Python code via a button in the Minitab interface. If you’re not a programmer, fear not! I’m no programmer myself, so if I can do this, you can too.
In this post, I’ll walk through the steps to add a custom menu with a button to execute a Python script that will generate a QQ plot and display the results in Minitab’s output pane.
If you’re a coding wizard, this example is very simple but will give you a feel for how easily you could set up something similar for others in your organization, allowing them take advantage of your custom code. You’ll be a hero!
First Things First: Let's Get Python Up and Running
This feature is available starting with Minitab 19.2020.1, and you’ll need Python 3.6.1 or higher installed on your machine. You can find all the details about connecting Minitab to Python here.
The Python script to generate the QQ plot, along with the necessary commands to send your data from Minitab to Python and return the results to Minitab are shown below:
You can also download the Python script above from here. I found the script to generate the QQ plot by searching the internet, which is easy to do for anyone that doesn’t want to learn to code. Note that the above code will retrieve the data for the QQ plot for column C1 in your Minitab worksheet.
Are You a Coding Whiz?
Set the Python File Location in Minitab
We’ll start by telling Minitab where to find your Python script, using this menu path: File > Options. In the new window, browse to the Default file location where you saved the script. Minitab will look for your Python script in the folder you specify.
Make a New Custom Minitab Menu
- Choose View > Customize.
- On the Commands tab, from the Categories list, select New Menu, then from the Commands list, select New Menu.
- While the Customize dialog box is open, drag New Menu to where you want it to appear in the Minitab interface. When the insertion point appears, release the mouse button.
- From the new menu's location in the Minitab interface, right-click New Menu and choose Name Button. Enter a name for your custom menu, for example, Python Scripts, and click OK.
- Click Close.
Are you still with me? Nice work! You’re almost there!
Create a Minitab Exec Macro to Call Your Python Script
Now, open a new Windows notepad file and type in the following commands:
PYSC "QQ_plot.py"
This PYSC command tells Minitab to call Python, and to run the QQ plot script. PYSC is the Minitab command, and the value between the double-quotes is the name of the script you want to execute.
To save the commands in the Minitab exec, save the text file and title it QQ_Plot.MTB (be sure to save it with .MTB and not .txt). Save the file to the Default file location where the Python script is saved (the same location you set in Minitab using File > Options):
Excellent job! Next, we’ll create a command to run a Minitab exec file.
Create a Command to Run a Minitab Exec File
- Choose View > Customize.
- In the Customize dialog box, click the Tools tab.
- On the Tools tab, click the New (Insert) button .
- Type a name for the command (I titled my command QQ plot C1 so that I’ll remember that the data for this command should be in C1 in the worksheet), then press the Enter key.
- Click the Open button (...).
- From the file type drop-down list, select All (*.*).
- Browse to and select the exec file titled QQ_plot.MTB that you saved previously:
Finally, Add your Macro to Your Custom Menu and Make Your Minitab/Python QQ Plot!
- Choose View > Customize.
- In the Customize dialog box, click the Commands tab.
- From the Categories list, select a category.
- From the Commands list, select the command to add.
- While the Customize dialog box is open, drag the selected command to your custom menu in the Minitab interface.
- Click Close.
Fantastic! Are you still with me, and are you ready to see the results?
After adding some data to the Minitab worksheet (in column C1 if you’re using the script shared in this post), click the QQ Plot C1 button you created in your custom menu on the right, Python Scripts:
Minitab will send your data to Python, then Python will execute the code and send the graph back to the Minitab output pane:
Way to go! Minitab’s new Python integration feature and free open-source code make it easy for people like us, that may want access to some extra features but aren’t particularly interested in learning to code.
And if you haven’t yet tried Minitab 19.2020.1, get your free 30-day trial today!