Q:

How to create a circular 2D plot with matplotlib where function depends on the distance from the center of the image?

I have a function which is 1 dimensional (like in the picture below). I was checking all matplotlib tutorials but I couldn't find the solution for plotting a 1D data in 2D plot where all points which the same distance from the image center will have the same value. 
From function like this:

I would like to get something like this:

I was trying with Axes3D and imshow but they need (x,y) coordinates not r (distance from the center). Thanks!

A:

Essentially you need to evaluate your function on a cartesian grid. So instead of calling your function with the radius r, func(r), you would call it with the radius calculated from the grid nodes x and y, func(sqrt(x**2+y**2))
import numpy as np
import matplotlib.pyplot as plt

func = lambda r: np.sin(r)*np.exp(-r/10.)
r = np.linspace(0,50,151)

X,Y = np.meshgrid(np.linspace(-50,50,301),np.linspace(-50,50,301))
rad = lambda x,y: np.sqrt(x**2+y**2)
image = func(rad(X,Y)) 

fig, (ax,ax2) = plt.subplots(ncols=2)

ax.plot(r, func(r))

ax2.imshow(image, extent=[X.min(),X.max(),Y.min(),Y.max()])
plt.show()

