Get Started with Matplotlib in Python to Visualize Data Collected from Measurement InstrumentsOctober 24, 2015 by Ujjwal Roy
This article explains how to install PyVisa and MatPlotlib for Python. PyVisa connects a computer to the measurement instruments and matplotlib helps to visualize the data collected from these instruments.
A Matter of Resolution
Instruments like oscilloscopes, signal generators, signal analyzers, and network analyzers can be very useful when it comes to hardware systems design and testing because of their higher accuracy in data reading and writing. The clock inside these instruments have much higher resolution than system clocks in Windows or even Linux: the default timer resolution in Windows is 15.6 ms. The reason for this resolution is to decrease power consumption and save battery life on Windows mobile devices. But this resolution is not enough when it comes to designing hardware systems.
Let’s take a Solid State Drive (SSD) testing scenario for an example. Timing is everything when it comes to data integrity in SSDs. The controller in these SSDs is programmed to schedule tasks that measure time in microseconds. If there is an unexpected power down in a computer, the SSD has a few miliseconds remaining (power provided by the holdup capacitors) to draw the data from DRAM and save it to NAND so that no data is lost. A Windows clock is not enough to go through these microseconds and verify if the SSD is behaving correctly or not. This is the reason why instruments are used because their timer resolution is in microseconds. For an example, the pulse width programming resolution of the B2900A SMU is 1 us.
Now, dealing in microseconds is really not possible for humans. All engineers want is the data of what happened during those microseconds. For this purpose, these measurement instruments can be programmed to take the measurements at certain times and report back in the form of data. Most instruments these days are programmable and they can accept Standard Commands for Programmable Instruments (SCPI; often pronounced "skippy"). SCPI commands can be used along with most of the popular languages like Java, C, C++, Python, etc. Among all these programming languages, Python has been chosen by multiple companies for its extensive spectrum of libraries.
Once the data is collected via these instruments, it need to be analyzed. Sometimes there's a huge amount of data, and simply going through all of it can be a very hectic and unproductive task. That is when data visualization comes into play. Python’s library matplotlib is a python plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. matplotlib can be used in python scripts, the python and ipython shell (ala MATLAB®* or Mathematica®), web application servers, and six graphical user interface toolkits. Figure 1 through 4 are some examples of what matplotlib can do.
Connecting the Instruments
PyVisa library in python is required to connect the measurement instrument to the PC. Python requires that you satisfy certain libraries and dependencies for Matplotlib and PyVisa to function completely. It can be fairly easy to download everything that is required for these library by using package managers like pip. But when you are at work in a corporate setting or in an office, package managers will not work, as most companies use proxy servers for various reasons that block package managers from downloading external packages on the system. In this case, PyVisa and Matplotlib have to be installed manually. However, the manual process can be tedious and very time consuming. PyVisa requires enum34 to be installed before PyVisa is installed. Matplotlib requires numpy, six, dateutil, and pyparsing to work flawlessly.
To simplify this, I collected all the dependencies setup and if you are unfamiliar with installing packages on Command Prompt, I have included at bat file that will automatically set up the PyVisa 1.7 and MatplotLib 1.4.3 along with its requirements. Simply download the .zip file and copy the unzipped folder in “My Documents.” Open the batch file, wait for the command prompt window to disappear, and you are all set.