gpt4 book ai didi

matplotlib - 使用 Julia 和 PyPlot 绘制球体

转载 作者:行者123 更新时间:2023-12-04 11:21:55 25 4
gpt4 key购买 nike

最近我尝试使用 PyPlot/Julia 绘制一个球体,不幸的是它比我想象的要难。
点生成可能有问题,但我不明白为什么我的实现不起作用。尽管使用原始 python 代码一切正常。

我已经尝试适应 demo2从 matplotlib 曲面图文档作为 MWE:

using PyPlot
u = linspace(0,2*π,100);
v = linspace(0,π,100);

x = cos(u).*sin(v);
y = sin(u).*sin(v);
z = cos(v);

surf(x,y,z)

我收到 this而不是 the right one.

那么,我的 Julia 实现到底出了什么问题?

最佳答案

这在 Julia 1.1.2 中不再适用于绘制球体。改用这个

using PyPlot
n = 100
u = range(0,stop=2*π,length=n);
v = range(0,stop=π,length=n);

x = cos.(u) * sin.(v)';
y = sin.(u) * sin.(v)';
z = ones(n) * cos.(v)';

# The rstride and cstride arguments default to 10
surf(x,y,z, rstride=4, cstride=4)

关于matplotlib - 使用 Julia 和 PyPlot 绘制球体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34821061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com