Plotting concentration constant over theta over an annulus in matplotlib not working as expected?

45 Views Asked by At

First-time poster, so apologies if the format or etiquette are not quite right.

I have been working on a code in a Jupyter Notebook that uses an Euler-explicit method to calculate simple unsteady diffusion. The details of the numerical scheme don't matter much, but I am doing the calculations in polar coordinates ranging from r=1 to r=10 with a step size of dr = 0.5. The concentration is going to be constant across theta, because there is no advection - essentially, C(r,t) and not C(r,theta,t). My issue is with plotting this in polar coordinates - it needs to be a polar plot, not Cartesian.

My numerical method gives me a vector of r-values and concentration values that look like this at the final time step:

r = [ 1.   1.5  2.   2.5  3.   3.5  4.   4.5  5.   5.5  6.   6.5  7.   7.5
  8.   8.5  9.   9.5 10. ]

C = [3.0, 2.9999999999971694, 2.999999999995282, 2.9999999999940608, 2.9999999999932836, 2.9999999999928395, 2.9999999999926175, 2.9999999999925064, 2.9999999999926175, 2.9999999999928395, 2.9999999999931726, 2.9999999999937277, 2.999999999994394, 2.999999999995171, 2.999999999995948, 2.9999999999969473, 2.9999999999979465, 2.9999999999989457, 3.0]

I have tried a thousand iterations of code to get a plot to come out correctly, but I keep having the same issue. This is my current code for a simple plot:

theta = np.linspace(0, 2 * np.pi, 360)  # Generate theta values
R, Theta = np.meshgrid(r, theta)
conc = np.array([C]*len(theta)).transpose() # C is constant over theta

fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))
ax.contourf(theta, r, conc)

plt.show()

And it displays this: Concentration values range from r=0 to r~3.5, and then from r~5.5 to r=10

Because my values for r only range from 1 to 10, and there is a concentration for each value of r, I don't understand why the figure is displaying concentrations from 0 to ~3.5, and then ~5.5 to 10. I've been going in circles (no pun intended) for days and I am losing my mind!

0

There are 0 best solutions below