The procedure for requesting AWR support has changed. Please read all about the new AWR product support process.
Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This code produces this graph:

Image RemovedImage Added

Further embellishments include adding titles, axis labels, grids and setting the axis ranges:

Code Block
languagepy
titleEmbellished graph
    #Create data
    x_ay = np.linspace(0,100,101)        #Create vector from 0 to 100 with 101 points
    y_ay = np.sin(2*np.pi*x_ay/100)      #Sine wave with 1 period over the x_ay range
    #
    plt.xlim([0,100])                    #x-axis range
    plt.ylim([-2,2])                     #y-axis range
    plt.title('Sine Wave', fontsize=16, fontweight='bold') #Plot title
    plt.xlabel('x-axis values', fontsize=14)  #x-axis label
    plt.ylabel('y-axis values', fontsize=14)  #y-axis label
    plt.grid(True, linestyle=':')             #Enable grid. Set linestyle to dots
    #
    plt.plot(x_ay, y_ay, color='r', linewidth=2) #plot with red trace color and specified width
    plt.show()                                   #Display plot window

Producing this output:

Image RemovedImage Added

Working with Graphs

...

This code produces this result from the installed example LPF_Lumped.emp

Image RemovedImage Added

Edit Graph Properties

...

Code Block
languagepy
titleScalar data read (Method 1)
	graph = project.Graphs('Passband and Stopband')
    meas = graph.Measurements('LPF:DB(|S(2,1)|)')
    
    #Method 1: Read measurment into an array
    MeasData_Tuple = meas.TraceValues(1)         #Returns set of (x,y) tuples for each data point
    MeasData_ay = np.asarray(MeasData_Tuple)     #numpy function to covert tuple into an array
    Freq_ay = MeasData_ay[:,0]                   #Extract x data vector
    s21_ay = MeasData_ay[:,1]                    #Extract y data vector
    plt.plot(Freq_ay, s21_ay)                    #Matplotlib plot function
    plt.show()                                   #Display graph window

Resulting Python graph:

Image RemovedImage Added

The second method is to read individual data points. For instance only select data points may want to be read instead of the entire measurement array.

...

The XValue() and YValue() methods are indexed beginning at a value of 1. The resulting graph looks like:

Image RemovedImage Added

Reading Multi-value Y-axis Data

...

Code Block
languagepy
titleComplex data read
    #Add new Smith Chart graph
    if project.Graphs.Exists('LPF Smith Chart'):   #Check to see if the Graph exists
        project.Graphs.Remove('LPF Smith Chart')   #Delete graph if it exists
    #end if 
	#
	#Add new Smith Chart graph   
    graph = project.Graphs.Add('LPF Smith Chart',mwo.mwGraphType.mwGT_SmithChart)
    meas = graph.Measurements.Add('LPF','S(1,1)')    #Add measurement
    project.Simulator.Analyze()                      #Simulate
    #
    MeasData_Tuple = meas.TraceValues(1)         #Returns set of (x, y_real, y_imag) tuples
                                                 #for each data point
    MeasData_ay = np.asarray(MeasData_Tuple)     #numpy function to covert tuple into an array
    Freq_ay = MeasData_ay[:,0]                   #Extract x-axis vector
    s11_Real_ay = MeasData_ay[:,1]               #Extract y-axis real vector
    s11_Imag_ay = MeasData_ay[:,2]               #Extract y-axis imaginary vector
    Legend_list = list()                         #Create list for plot legend
    #
    plt.plot(Freq_ay, s11_Real_ay, color='b')    #Plot real data
    Legend_list.append('s11 Real')               #Update legend
    plt.plot(Freq_ay, s11_Imag_ay, color='g')    #Plot imaginary data
    Legend_list.append('s11 Imaginary')          #Update legend
    #
    #Add legend to graph
    LegendHandle = plt.legend(Legend_list, loc='upper left', ncol=1)
    plt.setp(LegendHandle.get_texts(), fontsize=10)
    #
    plt.show()                                 

Resulting Python graph:

Image RemovedImage Added

The syntax for reading individual points for the y-axis data would be:

...

Code Block
languagepy
titleSWPVAR data read
    #Add SWPVAR to schematic to sweep the inductace value of INDQ.L3
    schem = project.Schematics('LPF')               #Point schem variable to the LPF schematic
    schem.Equations.Add('L3 = 33', 1000, -1300)     #Add equation at specific x,y location in schematic
    element = schem.Elements('INDQ.L3')             #Point element variable to inductor L3
    element.Parameters('L').ValueAsString = 'L3'    #Replace L parameter with the eqquation varaible
    element = schem.Elements.Add('SWPVAR',1000,-2000)   #Add SWPVAR element at specific location
    element.Parameters('Values').ValueAsString = 'swpstp(25,35,5)' #Set sweep parameters
    element.Parameters('VarName').ValueAsString = '"L3"'           #Set sweep variable
    project.Simulator.Analyze()                     #Simulate
    #
    graph = project.Graphs('Passband and Stopband')
    meas = graph.Measurements('LPF:DB(|S(1,1)|)')
    Ydata_list = list()
    SweepLabel_list = list()
    Legend_list = list()
    NumTraces = meas.TraceCount                      #Number of traces in the measurement
    for trace_idx in range(1, NumTraces+1):          #Loop through traces beginning at index 1
        MeasData_Tuple = meas.TraceValues(trace_idx) #Read data is Tuple for each data point
        MeasData_ay = np.asarray(MeasData_Tuple)     #numpy function to covert to array
        if trace_idx == 1:
            Freq_ay = MeasData_ay[:,0]
        #end if
        Ydata_list.append(MeasData_ay[:,1])
        #
        #Sweep label value
        SweepLabel_list.append(meas.SweepLabels(trace_idx).Item(1).Value)
    #
    #Sweep label name
    SweepLabel_Name = meas.SweepLabels(1).Item(1).Name
    #
    for trace_idx in range(NumTraces):
        plt.plot(Freq_ay, Ydata_list[trace_idx])
        Legend_list.append(SweepLabel_Name+' = '+str(SweepLabel_list[trace_idx]))
    #Add legend to graph
    #
    LegendHandle = plt.legend(Legend_list, loc='upper left', ncol=1)
    plt.setp(LegendHandle.get_texts(), fontsize=10)
    #
    plt.show()

Resulting Python graph:

Image RemovedImage Added

Working with Markers

...

The resulting AWRDE graph:

Image RemovedImage Added