How to: Make a Polar Plot in Python

Published: 03 September 2020
on channel: HagesLab
17,988
171

Learn how to make a 2D contour plot in Python in polar coordinates.

Script can be found here: https://www.hageslab.com/Resources.ht...

Here we are using "Spyder" IDE with the numpy and matplotlib libraries

Script:

import numpy as np
import matplotlib.pylab as plt

def T(theta,a,b):
return a*np.sin(theta*b)

def R(r,c,d):
return c*np.cos(r*d)

rlist=np.arange(0,4.01,0.01) #Angstroms
thetalist=np.radians(np.arange(0,361,1)) #Radians
rmesh, thetamesh = np.meshgrid(rlist, thetalist) #Generate a mesh

a = 1.5
b = 2
c = 2
d = 1.6

FullFunction = T(thetamesh,a,b)*R(rmesh,c,d)
FullFunction2 = FullFunction**2*rlist**2

fig, ax = plt.subplots(dpi=120,subplot_kw=dict(projection='polar'))
ax.contourf(thetamesh, rmesh, FullFunction, 100, cmap='plasma')

fig, ax = plt.subplots(dpi=120,subplot_kw=dict(projection='polar'))
ax.contourf(thetamesh, rmesh, FullFunction2, 100, cmap='plasma')


On this page of the site you can watch the video online How to: Make a Polar Plot in Python with a duration of hours minute second in good quality, which was uploaded by the user HagesLab 03 September 2020, share the link with friends and acquaintances, this video has already been watched 17,988 times on youtube and it was liked by 171 viewers. Enjoy your viewing!