相关疑难解决方法(0)

与matplotlib对称的streamplot

我正在尝试使用matplotlib绘制球体周围磁场的流线,它确实很好用.但是,生成的图像不是对称的,但应该是(我认为). 在此输入图像描述

这是用于生成图像的代码.请原谅,但我认为这比发布一个不起作用的片段更好.而且,它不是非常pythonic; 那是因为我从Matlab转换它,这比我预期的要容易.

from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Circle

def cart2spherical(x, y, z):
    r = np.sqrt(x**2 + y**2 + z**2)
    phi = np.arctan2(y, x)
    theta = np.arccos(z/r)
    if r == 0:
        theta = 0
    return (r, theta, phi)

def S(theta, phi):
    S = np.array([[np.sin(theta)*np.cos(phi), np.cos(theta)*np.cos(phi), -np.sin(phi)],
                  [np.sin(theta)*np.sin(phi), np.cos(theta)*np.sin(phi),  np.cos(phi)],
                  [np.cos(theta),             -np.sin(theta),             0]])
    return S

def computeB(r, theta, phi, a=1, muR=100, B0=1):
    delta = (muR - 1)/(muR + 2)
    if r …
Run Code Online (Sandbox Code Playgroud)

python matplotlib

11
推荐指数
3
解决办法
3497
查看次数

matplotlib 3d表面上的连续色调

在matplotlib 3D绘图中,我可以设置行/列的数量,以确定表面上可见的面的总数

s=ax.plot_surface(x,y,z, color='gray', shade=True, rstride=1,cstride=1)
Run Code Online (Sandbox Code Playgroud)

其中数字越小越好,但是面数越小.由于我也在这个表面上绘制流线/轨迹,我想摆脱脸的边缘.现在,随着

s.set_linewidth(0)
Run Code Online (Sandbox Code Playgroud)

设置较低的rstride和cstride值我几乎可以得到我想要的东西,即表面几乎连续变化的颜色,可以提供良好的3D效果.

不幸的是,线条留在那里,作为面之间的空位.有没有办法做到这一点?也许我只是错过了一个简单的命令..

编辑:生成曲面的代码很长,无法在此处报告.我附上了上面写的解决方法的结果快照.表面有白线

3d matplotlib

6
推荐指数
1
解决办法
7595
查看次数

标签 统计

matplotlib ×2

3d ×1

python ×1