1

I would like to plot a heatmap of y=f(r,phi). The code I use is to get the values,

import numpy as np
h1=1.7 
h2=0.5 
inclination=np.pi/6

def power(inclination,phi):
    h1=1.7 
    h2=0.5 
    D = np.arange(0.5, 12.0, 0.1)
    r = np.sqrt((h1-h2)**2 + D**2)
    freq = 865.7 
    lmb = 300/freq 
    H = D**2/(D**2+2*h1*h2)
    theta = 4*np.pi*h1*h2/(lmb*D)
    q_e = H**2*(np.sin(theta))**2 + (1 - H*np.cos(theta))**2
    sigma = 1.94
    N_1 = np.random.normal(0,sigma,D.shape)
    rnd = 10**(-N_1/10)
    F = 10 
    power=0.2

    alpha=inclination + np.arcsin((h1-h2)/r)
    gain=3.136*(np.tan(alpha)*np.sin(np.pi/2*np.cos(alpha)*np.sin(phi)))**2
    y=10*np.log10( 1000*(power*gain*1.622*((lmb)**2) *0.5*1) / (((4*np.pi*r)**2) *1.2*1*F)*q_e*rnd )
    return (r,phi,y)

phi=np.linspace(0, np.pi,num=115) + 10e-14

x,y,z = power(np.pi/6,phi)

I could plot the heatmap doing a meshgrid of x and y (i.e. r and phi)

X, Y = np.meshgrid(x, y)
X.shape 
Y.shape

gives (115, 115) both. I would need to reshape z values in the meshgrid before calling contourf() but I do not know how to do it.

user1993416
  • 698
  • 1
  • 9
  • 28

1 Answers1

0

The trick consists in to compute the function values using the meshgrid datapoints:

inclination = np.pi/6

def power(inclination,phi):
    h1=1.7 
    h2=0.5 
    D = np.arange(0.5, 12.0, 0.015)
    r = np.sqrt((h1-h2)**2 + D**2)
    freq = 865.7 
    lmb = 300/freq 
    H = D**2/(D**2+2*h1*h2)
    theta = 4*np.pi*h1*h2/(lmb*D)
    q_e = H**2*(np.sin(theta))**2 + (1 - H*np.cos(theta))**2
    sigma = 1.94
    N_1 = np.random.normal(0,sigma,D.shape)
    rnd = 10**(-N_1/10)
    F = 10 
    power=0.8
    R,PHI = np.meshgrid(r,phi[1:-1])

    alpha=inclination + np.arcsin((h1-h2)/R)
    gain=3.136*(np.tan(alpha)*np.sin(np.pi/2*np.cos(alpha)*np.sin(PHI)))**2
    y=10*np.log10( 1000*(power*gain*1.622*((lmb)**2) *0.5*1) / (((4*np.pi*R)**2) *1.2*1*F)*q_e*rnd )
    return (R,PHI,y)
user1993416
  • 698
  • 1
  • 9
  • 28