Makie.jl 中的绘图属性

编程入门 行业动态 更新时间:2024-10-08 18:34:42
本文介绍了Makie.jl 中的绘图属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我想通过 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.:

如何移动相机?(update_camera! 需要 Scene,但 axLScene.我不知道这是什么.)如何调整轴(标签、刻度等)?如何添加颜色条?如何保存图形? How to move the camera? (update_camera! needs Scene, but ax is LScene. I don't know what this is.) How to adjust the axis (labels, ticks, etc.)? How to add the colorbar? 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,有更多人可以提供帮助,很多快得多.

also, consider joining https://discourse.julialang, 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 中的绘图属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-27 14:57:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1157070.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   Makie   jl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!