Smith Plot Visualization in Matplotlib using Python
In this tutorial, we will learn a visualization chart known as the Smith Chart using Matplotlib in Python. We will understand what Smith plots are, why are they used and what are their advantages and disadvantages. Then we will go for the implementation of this chart using Matplotlib/
In my previous tutorial, I have shown Wind Rose Plot Visualization in Matplotlib using Python
Introduction to Smith Chart
The Smith Chart is a visualization method that is used to understand Radio Frequency signals in advanced Engineering. It is a circular graph used to represent complex impedance and admittance values. Impedance and Admittance are electrical terms used, let me define both the terms for you in simpler terms below.
- Impedance: This is simply a measure of how much a circuit resists the flow of electric current. For instance, driving on a rough path (resistance) will surely affect your speed (current).
- Admittance: This is the opposite of Impedance. Instead of measuring how a circuit resists the current, admittance measures how easily current can flow through a circuit. For instance, driving on a smooth road/path.
So in simple words, the Smith chart is a visualization of Impedance and Admittance involved in the circuit.
Application of Smith Chart
There are many applications of the Smith Chart in the real world. One of them is in developing RF (Radio Frequency) Circuits. This helps in understanding the Impedance (Resistance) in the circuits to help understand how efficient the RF circuit is.
Advantages of Smith Chart
The circular layout of the Chart makes the chart visually appealing which makes it easier for engineers to understand and analyze RF circuits. This chart helps to understand Impedance (Resistance) in the circuits which can help engineers to understand what components to adjust for smoother current flow.
Disadvantages of Smith Chart
Even though I mentioned that the circular layout makes it easy to understand RF circuits for engineers still it can get very complex for beginners to understand and read without prior engineering knowledge.
Code Implementation of Smith Chart
In this section, we will implement visualization of the Smith chart. We will start by creating a dataset that needs to be plotted and then go ahead with a basic chart as of now.
Data Creation for Impedance Values
Before, creating the dataset, let’s understand what data are we exactly creating for this plot. In terms of Engineering, the formula for Impedance in a circuit is given by: Z=R+jX
where,
Resistance (R) is similar to the friction that slows down the flow of electricity.
Reactance (X) is similar to Resistance but this is caused by any additional component in the circuit
Let’s start by creating a dataset for the visualization using the code snippet below. We will be creating random linspace
points for R
and X
values and then create a meshgrid
to map both the values and then with the help of the formula generate Impedance values.
R = np.linspace(0, 1, 5) X = np.linspace(-1, 1, 5) R, X = np.meshgrid(R, X) Z = R + 1j*X
Visualizing the Impedance Data
We will try to understand one of the most basic charts using the code snippet below. We have only one set of values to be plotted i.e. Impedance but we have at least two axes in a plot. Wondering how we will plot a visualization in this case? But you might have forgotten one major point, the single variable is a combination of two different variables and has one real and one imaginary part. Hence, we will visualize the real
part of the complex impedance against the imaginary
part.
plt.figure(figsize=(5, 5)) plt.plot(np.real(Z), np.imag(Z), 'r') plt.xlabel('Real(Z)') plt.ylabel('Imag(Z)') plt.title('Basic Smith Chart') plt.grid(True) plt.show()
The resulting plot after code execution is as follows:
But this plot is not circular, right? To achieve that, we have to make a very minor change in the code where we use the polar
function instead of plot
function. Have a look at the code snippet below.
plt.figure(figsize=(5, 5)) plt.polar(np.real(Z), np.imag(Z), 'r') plt.xlabel('Real(Z)') plt.ylabel('Imag(Z)') plt.title('Circular Smith Chart') plt.grid(True) plt.show()
The resulting plot after code execution is as follows:
Adding Minor Customization to the Smith Chart
We will add some minor custom design factors to the Smith plot to make it more visually appealing. Have a look at the code snippet below. We will plot each element of the plot separately and add their custom features like colors, sizes, and values.
plt.figure(figsize=(5, 5)) # Plot Basic Polar plot plt.subplot(111, projection='polar') # Instead of lines plot data points plt.plot(np.angle(Z), np.abs(Z), 'mo', markersize=5) # Add Circular grid lines plt.grid(color='green', linestyle='dashdot', linewidth=1) plt.title('Customized Circular Smith Chart') plt.tight_layout() plt.show()
The resulting plot after code execution is as follows:
I hope you liked this tutorial and learned something new through this tutorial as well. Have a look at the tutorial below as well.
- Data Visualizations But Animated – Python
- Venn Diagram in Python Programming
- Create a Pie chart using Plotly in Python
Happy Learning!
Leave a Reply