Makie.jl 中的绘图属性

Plot Attributes in Makie.jl

我想通过 HeatMap 在 xyz-space 中绘制函数 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)
end
fig, 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

这段代码已经帮了大忙,但还有一点问题。:

  1. 如何移动相机? (update_camera!需要Scene,但是axLScene。我不知道这是什么。)
  2. 如何调整坐标轴(标签、刻度等)?
  3. 如何添加彩条?
  4. 如何保存图形?

再次。 我做了另一个例子。这个真的很快。那里有您想要的大部分选项。

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. 
end