Book Image

Sage Beginner's Guide

By : Craig Finch
1 (1)
Book Image

Sage Beginner's Guide

1 (1)
By: Craig Finch

Overview of this book

Table of Contents (17 chapters)
Sage Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – improving polar plots


In a previous example, we made polar pots with the Sage function polar_plot. However, polar plots in matplotlib look nicer because they are plotted on special axes. Let's use matplotlib to make these plots again. This example uses the Pyplot interface to matplotlib:

import numpy
import matplotlib.pyplot as plt

# Repeat the antenna pattern example with the Pyplot interface
N = float(7)
theta = numpy.arange(0, numpy.pi, numpy.pi/100)
def normalized_element_pattern(theta):
    return abs(numpy.sin(theta))

def array_factor(theta, N):
    return abs(float(1 / N) * numpy.sin(float(N * pi / 2)
        * numpy.cos(theta))
        / numpy.sin(float(pi / 2) * numpy.cos(theta)))

plt.figure(figsize=(6, 4))
plt.subplot(121, polar=True)
plt.polar(theta, normalized_element_pattern(theta))
plt.title('Element factor')

plt.subplot(122, polar=True)
plt.polar(theta, array_factor(theta, N), color='red',
    label="Array factor")
plt.polar(theta, array_factor(theta...