我想用HeatMap在xyz空间中画一个函数f(x,y,z)。
下面是https://lazarusa.github.io/BeautifulMakie/surfWireLines/RGBcube/编写的代码。
using GLMakie, GeometryBasics, Colors
positions = vec([(i, j, k) for i=1:L,j=1:L,k=1:L]) #3D coordinate
F = zeros(Float64,length(positions)
for i = 1:length(positions) #convert f(x,y,z) to an array
x = positions[i][1]
y = positions[i][2]
z = positions[i][3]
F[i] = f(x,y,z)
endfig, ax = mesh(HyperRectangle(Vec3f0(positions[1]...),Vec3f0(0.8)), color = RGBA(0,0,F[1],0.5), transparency = false) #HyperRectangle(::position,::length),color=(::red,::green,::blue,::alpha)
wireframe!(ax,HyperRectangle(Vec3f0(positions[1]...), Vec3f0(0.8)), linewidth = 0.1, overdraw = false)
for i in 2:length(positions)
mesh!(ax, HyperRectangle(Vec3f0(positions[i]...), Vec3f0(0.8)), color = RGBA(0,0,F[i],0.5))
wireframe!(ax, HyperRectangle(Vec3f0(positions[i]...), Vec3f0(0.8)), linewidth = 0.1, overdraw = false)
end
fig这段代码起到了很大的作用,但仍然存在一些小问题。
update_camera!需要Scene,但ax是LScene。我不知道这是什么)发布于 2021-08-08 14:04:22
再来一次。我做了另一个例子。这个真快。在那里,你有你想要的大部分选择。
https://lazarusa.github.io/BeautifulMakie/surfWireLines/volumeScatters/
对于定制的蜱类,您可以始终这样做。
ax.xticks = ([1,2,3], ["1","2", "3"])另外,考虑一下加入https://discourse.julialang.org,那里有更多的人可以帮助,要快得多。
这里也有完整的代码。
# by Lazaro Alonso
using GLMakie
let
x = 1:10
y = 1:10
z = 1:10
f(x,y,z) = x^2 + y^2 + z^2
positions = vec([(i, j, k) for i in x,j in y, k in z])
vals = [f(ix,iy,iz) for ix in x, iy in y, iz in z]
fig, ax, pltobj = meshscatter(positions, color = vec(vals),
marker = FRect3D(Vec3f0(0), Vec3f0(10)), # here, if you use less than 10, you will see smaller squares.
colormap = :Spectral_11, colorrange = (minimum(vals), maximum(vals)),
transparency = true, # set to false, if you don't want the transparency.
shading= false,
figure = (; resolution = (800,800)),
axis=(; type=Axis3, perspectiveness = 0.5, azimuth = 7.19, elevation = 0.57,
xlabel = "x label", ylabel = "y label", zlabel = "z label",
aspect = (1,1,1)))
cbar = Colorbar(fig, pltobj, label = "f values", height = Relative(0.5))
xlims!(ax,-1,11)
ylims!(ax,-1,11)
zlims!(ax,-1,11)
fig[1,2] = cbar
fig
#save("fileName.png", fig) # here, you save your figure.
endhttps://stackoverflow.com/questions/68676269
复制相似问题