Python Forum
Free space loss 3D Plot - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Free space loss 3D Plot (/thread-29907.html)



Free space loss 3D Plot - scimi - Sep-25-2020

Hello everyone
I have the function:

#free space loss calculation
def fspl(d, f): 
    x = 4*math.pi
    ls = 3*10**8
    result = 20*math.log10(d)+20*math.log10(f)+20*math.log10(x/ls)
    return result
and two of the axis:
f = np.linspace(0,10000)
d = np.linspace(0,1000000)

How can I plot this into a 3D Surface with the axis frequency (y), distance (x) and free space loss (z)?

Thanks a lot for your help already in advance!


RE: Free space loss 3D Plot - scimi - Sep-25-2020

I proceeded a bit and got the following code but there is still an error 'only size-1 arrays can be converted to Python scalars'. What's wrong with my code?

import math
from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt
ax = plt.axes(projection='3d')

def function(d, f):
    x = 4*math.pi
    ls = 3*10**8
    test = 20*math.log10(d)+20*math.log10(f)+20*math.log10(x/ls)
    return test

x = np.linspace(0,10, 100)
y = np.linspace(0,10, 100)

X,Y = np.meshgrid(x,y)
Z = function(X,Y)

ax.plot_surface(X,Y,Z)
plt.show()