Plotting a Limacon

This is a program that plots the shape of a limacon for r = 0.8, r = 1.0, and r = 1.2

In [1]:
import matplotlib.pyplot as plt
from pandas import Series, DataFrame
import pandas as pd
import numpy as np

def main():
    print()
    print("This is a program that plots the shape of a limacon for r = 0.8, r = 1.0, and r = 1.2")
    print()
#------------------------------------------------------------------------------    
    x = np.linspace(0, 2*np.pi, 100)                            #create curve for r = 0.8
    r = 0.8 + np.cos(x)
    w,y = r * np.cos(x), r * np.sin(x)
    
    
    fig1 = plt.figure()
    
    hw1 = fig1.add_subplot(1,1,1)
    hw1.plot(w,y, label = 'r = 0.8')
#-----------------------------------------------------------------------------    
                                                              #create curve for r = 1.0
    r = 1.0 + np.cos(x)
    z,k = r * np.cos(x), r * np.sin(x)

    hw2 = fig1.add_subplot(1,1,1)
    hw2.plot(z,k, label = 'r = 1.0')
#-----------------------------------------------------------------------------    
    r = 1.2 + np.cos(x)                                      #create curve for r = 1.2
    j,m = r * np.cos(x), r * np.sin(x)

    hw3 = fig1.add_subplot(1,1,1)
    hw3.plot(j,m, label = 'r = 1.2')
#-----------------------------------------------------------------------------    
    hw1.set_title('Plotting a limacon')                         #create labels, legends, and x y limits for plot
    hw1.legend(loc = 'best')
    hw1.set_ylabel('r * sin')
    hw1.set_xlabel('r * cos')
    hw1.set_ylim([-1.5,2.0])
    hw1.set_xlim([-0.5, 3.0])
#-----------------------------------------------------------------------------
    plt.show()                                                #show plot
    
main()
This is a program that plots the shape of a limacon for r = 0.8, r = 1.0, and r = 1.2