本文介绍了Makie.jl 中的绘图属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过 HeatMap 在 xyz 空间中绘制函数 f(x,y,z).
我有以下代码 https://lazarusa.github.io/BeautifulMakie/surfWireLines/RGBcube/ .

I'd like to plot a function f(x,y,z) in xyz-space by HeatMap.
I have the following code by 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

这段代码大有帮助,但仍然有一个小问题.:

This code has mostly helped, but there's still a little problem.:

  1. 如何移动相机?(update_camera! 需要 Scene,但 axLScene.我不知道这是什么.)
  2. 如何调整轴(标签、刻度等)?
  3. 如何添加颜色条?
  4. 如何保存图形?
  1. How to move the camera? (update_camera! needs Scene, but ax is LScene. I don't know what this is.)
  2. How to adjust the axis (labels, ticks, etc.)?
  3. How to add the colorbar?
  4. How to save the figure?

推荐答案

再次.我又做了一个例子.这个速度真的很快.在那里,您拥有大部分想要的选项.

again.I did another example. This one is really fast. There, you have most of the options you want.

https://lazarusa.github.io/BeautifulMakie/surfWireLines/volumeScatters/

对于自定义刻度,您可以随时进行

For custom ticks, you can always do

ax.xticks = ([1,2,3], ["1","2", "3"])

另外,考虑加入https://discourse.julialang.org,有更多人可以提供帮助,很多快得多.

also, consider joining https://discourse.julialang.org, there more people could help, much much faster.

这里也有完整的代码.

# 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

这篇关于Makie.jl 中的绘图属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 05:03