Using scikit-rf plotting SMith Chart with normalized to 50 Ohms

65 views
Skip to first unread message

Dennis

unread,
Apr 29, 2023, 10:36:20 AMApr 29
to scikit-rf
Hey, I have a question regarding the SmithChart. Is it possible normilize the values to 50 Ohm and get this values in a new touchstone file?

Dennis

unread,
Apr 29, 2023, 3:40:14 PMApr 29
to scikit-rf
       data = rf.Network(File)

        idx_start = np.abs(data.f - (plot_data_s2p[0][2]*1000000)).argmin()
        idx_stopp = np.abs(data.f - (plot_data_s2p[0][3]*1000000)).argmin()
        freq = rf.Frequency(start=data.f[idx_start], stop=data.f[idx_stopp])
        freq_new = data.frequency[idx_start:idx_stopp]

        data_new = data.interpolate(freq_new)
        data_new.s11.plot_s_smith(ax=ax0, label = filenames[counter_filename], linewidth=0.9, draw_labels=True)  

mhuser

unread,
Apr 29, 2023, 4:44:10 PMApr 29
to scikit-rf
If the data are not normalized to 50 ohm, it is possible to renormalize them:
data_normalized = data.copy()
data_normalized.renormalize([50, 50])
data_normalized.write_touchstone(filename = 'example.s2p')
Network.write_touchstone

Dennis

unread,
Apr 29, 2023, 4:57:51 PMApr 29
to scikit-rf
The data is normalized to 50 ohm, I can convert them with data.s11.z to the impedance as that I know, but I want to draw the labels on the Smith Chart also to 50 Ohm and not normalized to 1
Message has been deleted

mhuser

unread,
Apr 29, 2023, 6:26:42 PMApr 29
to scikit-rf
plot_z_smith(...) does not exist.
But if you want to replace the 1 with 50 you can call the plotting function manually:

import skrf as rf
from matplotlib import pyplot as plt
rf.stylely()

plt.figure()
rf.plotting.smith(draw_labels = True, ref_imm = 50.0)
rf.plotting.plot_smith(n.s[:, 0, 0], title = None, x_label = None, y_label = None, label = 's11')

smithchart.png

mhuser

unread,
Apr 29, 2023, 6:30:31 PMApr 29
to scikit-rf
This should also works:
plt.figure()
rf.plotting.smith(draw_labels = True, ref_imm = 50.0)
data.plot_s_smith(0, 0)

Dennis

unread,
Apr 30, 2023, 5:09:03 AMApr 30
to scikit-rf
That is working for me, thanks a lot. But I got another problem in regards. If I put  draw_labels = False the markers with scatter and annote are getting plottet and if I put  draw_labels = True they will not beeing plottedUnbenannt.PNGUnbenannt1.PNG

        filenames.append(os.path.basename(os.path.splitext(File)[0]))              

        data = rf.Network(File)

        idx_start = np.abs(data.f - (plot_data_s2p[0][2]*1000000)).argmin()
        idx_stopp = np.abs(data.f - (plot_data_s2p[0][3]*1000000)).argmin()
        freq = rf.Frequency(start=data.f[idx_start], stop=data.f[idx_stopp])
        freq_new = data.frequency[idx_start:idx_stopp]

        data_new = data.interpolate(freq_new)
        rf.plotting.smith(ax=ax0, draw_labels = False, ref_imm = 50, chart_type='z')
        data_new.s11.plot_s_smith(ax=ax0, label = filenames[counter_filename],  linewidth=0.9)        
        leg1 = ax0.legend(loc="upper right", fontsize= 6)  
               
        lines = ax0.get_lines()
        colors = [line.get_color() for line in lines]
        new_colors = colors[3:]
        table_colors = np.repeat(new_colors, 3)
       
        if table_s11 == 1:
            s11_points = []
            s11_points_index = []
            for i in range(len(plot_data_s2p[3])):
                s11_points = np.append(s11_points, np.interp(plot_data_s2p[4][i]*10e5, data.f, np.squeeze(data.s11.s)))
               
         
            print(s11_points)
            # Add Marker
            for i in range(len(plot_data_s2p[3])):  
                ax0.scatter(s11_points.real[i], s11_points.imag[i], marker = '.', s=20, color=new_colors[counter_filename])
                ax0.annotate(plot_data_s2p[6][i], (s11_points.real[i], s11_points.imag[i]), xytext=(-7, 7), textcoords='offset points', color=new_colors[counter_filename])  

mhuser

unread,
Apr 30, 2023, 6:18:28 AMApr 30
to scikit-rf
Nice plot!
Strange, this works for me:
fig, ax0 = plt.subplots()
rf.plotting.smith(ax = ax0, draw_labels = True, ref_imm = 50.0, chart_type = 'z')
n.plot_s_smith(ax = ax0)
leg0 = ax0.legend(loc="upper right", fontsize= 6) 
ax0.scatter(n.s.real[1, 0, 0], n.s.imag[1, 0, 0], marker = '.', s=20, color='r')
ax0.annotate('M1', (n.s.real[1, 0, 0], n.s.imag[1, 0, 0]), xytext=(-7, 7), textcoords='offset points', color='r')
Figure_1.png

Dennis

unread,
Apr 30, 2023, 3:43:28 PMApr 30
to scikit-rf
I found my problem: Sadly it was the color iterate with lines = ax0.get_lines() colors = [line.get_color() for line in lines]. 
I don't know, but it took weird colours and every fourth colour was my line colour. I fixed it by new_colors = colors[4::5]. 
the first element of the array is always a white colour in regards I couldn't see any Markers on the plot beacause it was white :D.


        filenames.append(os.path.basename(os.path.splitext(File)[0]))              
        data = rf.Network(File)

        idx_start = np.abs(data.f - (plot_data_s2p[0][2]*1000000)).argmin()
        idx_stopp = np.abs(data.f - (plot_data_s2p[0][3]*1000000)).argmin()
        freq = rf.Frequency(start=data.f[idx_start], stop=data.f[idx_stopp])
        freq_new = data.frequency[idx_start:idx_stopp]
        data_new = data.interpolate(freq_new)
       
        rf.plotting.smith(ax=ax0, draw_labels = True, ref_imm = 50, chart_type='z')
        data_new.s11.plot_s_smith(ax=ax0, label = filenames[counter_filename],  linewidth=0.9)        
        leg1 = ax0.legend(loc="upper right", fontsize= 6)  
   
        lines = ax0.get_lines()
        colors = [line.get_color() for line in lines]
        new_colors = colors[4::5]
        table_colors = np.repeat(new_colors, 3)
       
        print(new_colors)

        if table_s11 == 1:
            s11_points = []
            s11_points_index = []
            for i in range(len(plot_data_s2p[3])):  
                s11_points_index = np.append(s11_points_index, np.abs(data.f - (plot_data_s2p[3][i]*1000000)).argmin())              
                s11_points = np.append(s11_points, np.interp(plot_data_s2p[3][i]*10e5, data.f, np.squeeze(data.s11.s)))

           
            # Add Marker
            for i in range(len(plot_data_s2p[3])):  
                ax0.scatter(data.s11.s.real[int(s11_points_index[i])], data.s11.s.imag[int(s11_points_index[i])], marker = '.', s=20, color=new_colors[counter_filename])
                ax0.annotate(plot_data_s2p[6][i], (data.s11.s.real[int(s11_points_index[i])], data.s11.s.imag[int(s11_points_index[i])]), xytext=(-7, 7), textcoords='offset points', color=new_colors[counter_filename])
                           
            s11_points_legend = []          
            for i in range(len(plot_data_s2p[3])):
                s11_points_legend = np.round(np.append(s11_points_legend, np.interp(plot_data_s2p[4][i]*10e5, data.f, np.squeeze(data.s11.z[:,0,0]))),2)
                legend_labels.append([plot_data_s2p[6][i], str(plot_data_s2p[3][i])+' MHz', str(np.round(s11_points_legend[i],3))])
        counter_filename = counter_filename + 1       


Unbenannt.PNG

mhuser

unread,
Apr 30, 2023, 4:06:06 PMApr 30
to scikit-rf
I'm glad it works. The plot looks very good and the display of the marker table with colours is excellent!
Reply all
Reply to author
Forward
0 new messages