# Plotting¶

## Introduction¶

This tutorial describes skrf’s plotting features.

If you would like to use skrf’s plot styling, use stylely

```In [4]: rf.stylely()
```

## Plotting Methods¶

Microwave network plotting functions are implemented as methods of the `Network` class. Some of the plotting functions of network s-parameters are,

Similar methods exist for Impedance (`Network.z`) and Admittance Parameters (`Network.y`),

Step-by-step examples of how to create and customize plots are given below.

## Complex Plots¶

### Smith Chart¶

As a first example, load a `Network` from the data module, and plot all four s-parameters on the Smith chart.

```In [5]: import skrf as rf

In [6]: from skrf.data import ring_slot

In [7]: ring_slot
Out[7]: 2-Port Network: 'ring slot',  75-110 GHz, 501 pts, z0=[ 50.+0.j  50.+0.j]

In [8]: ring_slot.plot_s_smith()
```

Note

If you dont see any plots after issuing these commands, then you may not have started ipython with the –pylab flag. Try **from pylab import * ** to import the matplotlib commands and ion() to turn on interactive plotting. See this page , for more info on ipython’s pylab mode.

Note

Why do my plots look different? See Formatting Plots

The smith chart can be drawn with some impedance values labeled through the draw_labels argument.

```In [9]: figure();

In [10]: ring_slot.plot_s_smith(draw_labels=True)
```

Another common option is to draw addmitance contours, instead of impedance. This is controled through the chart_type argument.

```In [11]: figure();

In [12]: ring_slot.plot_s_smith(chart_type='y')
```

See `smith()` for more info on customizing the Smith Chart.

Note

If more than one plot_s_smith() command is issued on a single figure, you may need to call `draw()` to refresh the chart.

### Complex Plane¶

Network parameters can also be plotted in the complex plane without a Smith Chart through `Network.plot_s_complex()`.

```In [13]: figure();

In [14]: ring_slot.plot_s_complex();
```

## Rectangular Plots¶

### Log-Magnitude¶

Scalar components of the complex network parameters can be plotted vs frequency as well. To plot the log-magnitude of the s-parameters vs. frequency,

```In [15]: figure();

In [16]: ring_slot.plot_s_db()
```

When no arguments are passed to the plotting methods, all parameters are plotted. Single parameters can be plotted by passing indices m and n to the plotting commands (indexing start from 0). Comparing the simulated reflection coefficient off the ring slot to a measurement,

```In [17]: from skrf.data import ring_slot_meas

In [18]: figure();

In [19]: ring_slot.plot_s_db(m=0,n=0) # s11

In [20]: ring_slot_meas.plot_s_db(m=0,n=0) # s11
```

### Phase¶

Plot phase,

```In [21]: figure();

In [22]: ring_slot.plot_s_deg()
```

Or unwrapped phase,

```In [23]: figure();

In [24]: ring_slot.plot_s_deg_unwrap()
```

The components the Impendanc and Admittance parameters can be plotted similarly,

```In [25]: figure();

In [26]: ring_slot.plot_z_im()
```
```In [27]: figure();

In [28]: ring_slot.plot_y_re()
```

## Customizing Plots¶

The legend entries are automatically filled in with the Network’s `name`. The entry can be overidden by passing the label argument to the plot method.

```In [29]: figure();

In [30]: ring_slot.plot_s_db(m=0,n=0, label = 'Simulation')

In [31]: ring_slot_meas.plot_s_db(m=0,n=0, label = 'Measured')
```

The frequency unit used on the x-axis is automatically filled in from the Networks `frequency` attribute. To change the label, change the frequency’s unit.

```In [32]: ring_slot.frequency.unit = 'mhz'
```

Other key word arguments given to the plotting methods are passed through to the matplotlib `plot()` function.

```In [33]: figure();

In [34]: ring_slot.plot_s_db(m=0,n=0, linewidth = 3, linestyle = '--', label = 'Simulation')

In [35]: ring_slot_meas.plot_s_db(m=0,n=0, marker = 'o', markevery = 10,label = 'Measured')
```

All components of the plots can be customized through matplotlib functions.

```In [36]: figure();

In [37]: ring_slot.plot_s_smith()

In [38]: xlabel('Real Part');

In [39]: ylabel('Imaginary Part');

In [40]: title('Smith Chart');

In [41]: draw();
```

## Saving Plots¶

Plots can be saved in various file formats using the GUI provided by the matplotlib. However, skrf provides a convenience function, called `save_all_figs()`, that allows all open figures to be saved to disk in multiple file formats, with filenames pulled from each figure’s title

```In [42]: rf.save_all_figs('.', format=['png','eps','pdf'])
./WR-10 Ringslot Array Simulated vs Measured.eps
./WR-10 Ringslot Array Simulated vs Measured.pdf
```

## Misc¶

A common need is to make a color plot, interpretable in greyscale print. The `add_markers_to_lines()` adds different markers each line in a plots after the plot has been made

```In [43]: figure();

In [44]: ring_slot.plot_s_db(m=0,n=0)

In [45]: ring_slot_meas.plot_s_db(m=0,n=0)

The function `skrf.util.stylely()` will attempt to update your rcParams so that your plots look like the ones in this tutorial.