Using streamplot function in Python for stretched grid

Viewed 31

I am trying to plot (magnetic) field lines. I came to know stream function is the tool used to plot field lines. However, an error comes up telling ValueError: 'x' values must be equally spaced.

Please note that the code uses Fourier basis along x so it is equally spaced along x and uses Chebyshev basis along y and hence it is non-uniform grid along y. I do not understand why the code says "x must be uniformly spaced" when it's uniform along x.

The other thing I want to know is, how to plot field lines for a non-uniform grid?

Also is there any other method to plot field lines apart from streamplot?

Code that I am running is attached below for reference:

import numpy as np
import h5py
import matplotlib.pyplot as plt

f = h5py.File('./B_mm/Re_10k/Bx_v24/Bx_v24_s1.h5', 'r')
y = f['/scales/y/1.0'][:]
x = f['/scales/x/1.0'][:]
Bxtotal = f['/tasks/Bxtotal'][:]
Bytotal = f['/tasks/Bytotal'][:]
t = f['scales']['sim_time'][:]
print(np.shape(y))
print('y = ', y)
print(np.shape(x))
print('x= ', x)

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

Bx = Bxtotal[len(Bxtotal)-1, :, :]
By = Bytotal[len(Bytotal)-1, :, :]
print(np.shape(Bx))
print(np.shape(By))

plt.figure(figsize=(4,4),facecolor="w")
plt.streamplot(X, Y, Bx, By, color='k', density=1.3, minlength=0.9, arrowstyle='-')
plt.show()

And this is my error message; Error message

0 Answers
Related