0

I'm trying to plot a Bessel function in 2D using the scipy.quad integration method.

My problem: the plot only has a tiny dot in the middle because my lowest value is far too low.

Here is my code:

import numpy as np
import scipy.integrate as si
import matplotlib.pyplot as plt

wavelength = 5.0
k = 2 * np.pi / wavelength

side = 100.0
points = 100
spacing = side / points


def J(x, m):
    def f(t):
        return np.cos(m * t - x * np.sin(t)) / np.pi

    y = si.quad(f, 0, np.pi)
    return y[0]


x1 = side / 2
y1 = side / 2


data = np.empty([points, points], float)
data[0, 0] = 0.5

for i in range(1, points):
    y = spacing * i
    for j in range(1, points):
        x = spacing * j
        r = np.sqrt((x - x1) ** 2 + (y - y1) ** 2)
        if r == 0:
            data[i, j] = 1
        else:
            data[i, j] = (2 * J(1, r) / r) ** 2
print(data.min(), data.max())
plt.imshow(data, origin="lower", extent=[0, side, 0, side])
plt.show()
Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
  • Welcome to Stack Overflow! Other users marked your question for low quality and need for improvement. I re-worded/formatted your input to make it easier to read/understand. Please review my changes to ensure they reflect your intentions. But I think your question is still not answerable. **You** should [edit] your question now, to add missing details (see [mcve] ). Feel free to drop me a comment in case you have further questions or feedback for me. – GhostCat Oct 09 '18 at 03:53
  • Meaning: you should include some input / output examples that show what you expect, and what comes out your code. – GhostCat Oct 09 '18 at 03:54

0 Answers0