I'm trying to create a 3D plot showing fields lines going through a surface which can be tilted using Python. For the field lines, I wish to create them based on a field vector, displayed using quiver. The arrows in the plot seem to be of very low resolution, any suggestions on how to improve this? Any help would be much appreciated!
Here is my code;
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
angle = 0 #
b_y = np.cos(angle*np.pi/180) #
b_z = np.sin(angle*np.pi/180) #
l = np.array([1,0,0]) #
b = np.array([0,b_y,b_z]) #
A = np.cross(l,b) #
l_ = np.linalg.norm(l) #
b_ = np.linalg.norm(b) #
A_ = np.linalg.norm(A) #r
# Plot
plt.figure(1)
ax = plt.axes(projection="3d")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_zlim(0, 1)
# Surface
n = 100
x_l =np.linspace(0,b[1], n)
y_b = np.linspace(0,1, n)
z_z = np.linspace(0,b[2],n)
xx, yy = np.meshgrid(x_l, y_b)
zz = (xx+yy)/(xx+yy) + z_z -1
ax.plot_surface(xx, yy, zz, alpha=0.5)
B = np.array([0,0,1]) # Field vector
flux = np.dot(A,B) # Flux
m = 4
# Plot field lines
for x in range(0,m+1):
for y in range(0,m+1):
#ax.plot3D([x*b_/m,x*b_/m],[y*l_/m,y*l_/m],[0,1], color='purple')
ax.quiver(y/m,x/m, np.zeros(n), B[0], B[1], B[2], length=0.1, normalize=True, color='purple')
plt.savefig('3Dplot1.png',dpi=300)
plt.show()
Each arrow is 100 arrows. I don't really follow your code, nor why you would use a for loop to draw arrows one by one. Maybe this 100 arrows is a rest of a previous attempt to draw all of them without for loops. Which you should indeed.
But, in the meantime replacing
by
Reduce the low quality impression you get when you draw 100 times the same arrow at the same place.
Note that it is deterministic. So it is not like there was noise on arrow position or anything. Simply, there is an anti-aliasing when you draw something. Which makes some pixels semi-transparent, to create an anti-aliasing independent from the background. But if you draw 100 times the exact same arrow, with the exact same semi-transparent anti-aliasing pixels, you get something more binary: either a pixels is drawn, or it is not. In other words, it ends up like drawing 1 single arrow without anti-aliasing.
Image with 1 arrow instead of 100. Not easy to spot the difference with images here, but we can see that indeed, there is anti-aliasing on arrow end in mine and not in yours.