Video není dostupné.
Omlouváme se.
How to: Make a Polar Plot in Python
Vložit
- čas přidán 2. 09. 2020
- Learn how to make a 2D contour plot in Python in polar coordinates.
Script can be found here: www.hageslab.c...
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')
Awesome professor!! plz continue to post more and more videos. I watched all and found excellent. Thank you so much.
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.
Thank yopu for your video, but how are the numbers 3.5, 3, 2.5, 2 inside the plot generated?
Can you do this with R/Rstudio?
hi, do you know a method to do an animation of a contourf like this?
Thank you very much
Maybe this will help: stackoverflow.com/questions/23070305/how-can-i-make-an-animation-with-contourf/38401705
what's your function exactly?