使用makie.jl的朱莉娅(Julia)Contourf Colorbar的对数标度

发布于 2025-02-11 12:42:47 字数 983 浏览 1 评论 0原文

您如何处理Contourf图中的对数标度 julia 中的图? (使用makie.jl)我只想绘制一个二维数据文件,其值在10到10000范围内并使用对数Colorbar,但我找不到该方法。我已经看到,关于heatmap> ,关于Contourf,有一个关于此主题的公开问题。

假设我有字段v

julia> v
7×7 Array{Int64,2}:
    2   600    50     2   600    50     2
   50  7000  5000    50  7000  5000    50
  300    20    60   300    20    60   300
 5000     3    70  5000     3    70  5000
   70   150  1000    70   150  1000    70
 1000  8000     2  1000  8000     2  1000
 3000   500     1  3000   500     1  3000

如果我尝试使用makieCONTOURF绘制此字段,

julia> fig, ax, im = contourf(1:7, 1:7, v, levels=0:50:10000)
julia> Colorbar(fig[1,2], im)
julia> save("./plot.png", fim)

我得到了: “图1”

我的问题是我如何在colormap中使用对数标度colorbar ticks为了可视化小值之间的差异...

How do you deal with logarithmic scale in contourf plots in Julia? (using Makie.jl) I just want to plot a two-dimensional data file with values that range from 10 to 10000 and use a logarithmic colorbar, but I can't find how to do it. I have seen that there is an open question about this topic with heatmap but I couldn't find anything about contourf.

Let's say I have field v

julia> v
7×7 Array{Int64,2}:
    2   600    50     2   600    50     2
   50  7000  5000    50  7000  5000    50
  300    20    60   300    20    60   300
 5000     3    70  5000     3    70  5000
   70   150  1000    70   150  1000    70
 1000  8000     2  1000  8000     2  1000
 3000   500     1  3000   500     1  3000

If I try to plot this field with Makie and contourf

julia> fig, ax, im = contourf(1:7, 1:7, v, levels=0:50:10000)
julia> Colorbar(fig[1,2], im)
julia> save("./plot.png", fim)

I get this:
Figure 1

My question is how can I use a logarithmic scale in both colormap and colorbar ticks in order to visualize the the differences between small values...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乖乖兔^ω^ 2025-02-18 12:42:47

我想到的最好的解决方案是将您的值转换为日志空间。在这里:

using CairoMakie

# Generate a tool field
X1, X2 = 0:.1:5, 0:.1:5
X3 = [ 10 ^ x1 for x1 in X1, x2 in X2 ]
lvls = 10 .^ collect( X1 )

# Note: we apply log10 to field and levels!
fig = Figure()
ax = Axis( fig[1, 1] )
ctf = contourf!( ax, X1, X2, log10.( X3 ), levels = log10.( lvls[1:5:end] ) )

# We make the ticks string (non-log) match the ticks values (log)
ticks_val = log10.( lvls[1:5:end] )
ticks_str = string.( round.(lvls[1:5:end]; digits = 2) )    # Here we can even write by hand a nicer string that has exponents
Colorbar(fig[1,2], ctf, height = Relative(1/2), ticks = (ticks_val, ticks_str) )
fig

它应该给您这一点:

“

The best solution I came up with is transforming your values into the log space. Here it goes:

using CairoMakie

# Generate a tool field
X1, X2 = 0:.1:5, 0:.1:5
X3 = [ 10 ^ x1 for x1 in X1, x2 in X2 ]
lvls = 10 .^ collect( X1 )

# Note: we apply log10 to field and levels!
fig = Figure()
ax = Axis( fig[1, 1] )
ctf = contourf!( ax, X1, X2, log10.( X3 ), levels = log10.( lvls[1:5:end] ) )

# We make the ticks string (non-log) match the ticks values (log)
ticks_val = log10.( lvls[1:5:end] )
ticks_str = string.( round.(lvls[1:5:end]; digits = 2) )    # Here we can even write by hand a nicer string that has exponents
Colorbar(fig[1,2], ctf, height = Relative(1/2), ticks = (ticks_val, ticks_str) )
fig

It should give you this:

logarithmic field

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文