How to: Make a Polar Plot in Python

preview_player
Показать описание
Learn how to make a 2D contour plot in Python in polar coordinates.

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

Script:

import numpy as np

def T(theta,a,b):

def R(r,c,d):

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

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

Рекомендации по теме
Комментарии
Автор

Awesome professor!! plz continue to post more and more videos. I watched all and found excellent. Thank you so much.

researcher
Автор

This is a nice video. As usual, I am confused. I have never understood contourf and meshgrid. It seems to me that contourf should work with 1D arrays rlist and thetalist, and a function Z(r, theta). The function would be a 1D array of appropriate length = len(rlist)*len(thetalist). This seems completely defined, so I don't know what is accomplished with meshgrid. All I need to do is a nested loop that fills Z(r, theta) with each element of r and theta. I checked the documentation for contourf. It can accept 1D arrays, so why use meshgrid? Conceptually, I have trouble verifying that meshgrid is doing the right thing. A nested loop seems much easier to verify, because I explicitly pass in the r and theta values that I want to evaluate for Z. It's not always possible to generate a 2D array for Z, as done in the video. Sometimes, the function Z is complicated and cannot just take in 2D arrays directly. When that is the case, getting the correct Z function using meshgrid takes effort to understand exactly how meshgrid creates the grid. I basically have to reverse engineer meshgrid to fill Z. Very complicated. So, I try to work with 1D arrays and a nested loop. That always works and is simple conceptually, whereas the meshgrid technique might or might not work, depending on the function. What's really mind-bending for me is that meshgrid returns two 2D arrays, whereas conceptually a contour plot maps two numbers to a third number, not two 2D arrays to a third number. So, the meshgrid technique is much more confusing for me to validate and conceptualize.

amannucg
Автор

Thank yopu for your video, but how are the numbers 3.5, 3, 2.5, 2 inside the plot generated?

EG-rwge
Автор

hi, do you know a method to do an animation of a contourf like this?

Thank you very much

aureliencad