图:jl:更改logscale tick的更改形式为正常格式

发布于 2025-01-22 18:38:57 字数 1059 浏览 5 评论 0原文

考虑以下图

using Plots
pyplot()

radix_range_xticks = -4:4
radix_range = LinRange(-4, 4, 100)
xs = 2.0 .^ radix_range_xticks
pf = 50.0
bw = 25.0
roofline(x, bw, pf) = min(bw*x, pf)
ys = roofline.(xs, bw, pf)
p = plot(xs, ys; xscale=:log2, yscale=:log10)
xticks!(p, xs)

会导致图片的图。

X-Ticks和Y-Ticks都格式为指数。添加关键字参数xformatter =:Scientific无济于事,因为它只是更改radix而不是整个数字。

那么,我如何在科学符号中格式化tick呢?我想完全摆脱base^endegons符号。

我还尝试将字符串 s的迭代性传递到XTICKS!,但没有在其上派遣。

我试图看在文档中可能会有所帮助。

在Julia lang话语上进行交叉封闭“>在这里

Consider the following plot

using Plots
pyplot()

radix_range_xticks = -4:4
radix_range = LinRange(-4, 4, 100)
xs = 2.0 .^ radix_range_xticks
pf = 50.0
bw = 25.0
roofline(x, bw, pf) = min(bw*x, pf)
ys = roofline.(xs, bw, pf)
p = plot(xs, ys; xscale=:log2, yscale=:log10)
xticks!(p, xs)

This results in a plot that looks like this.

View of the plot

The x-ticks and y-ticks both are formatted as exponentials. Adding the keyword argument xformatter=:scientific does not help, as it just changes the radix instead of the whole number.

With xformatter=:scientific

So, how can I format the ticks in e.g. scientific notation? I would like to get rid of the base^exponent notation altogether.

I also tried passing an iterable of Strings to xticks!, but it does not dispatch on it.

I tried to look here in the documentation, but could not anything else that might help.

Crossposted on the Julia lang discourse here

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

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

发布评论

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

评论(2

嘿咻 2025-01-29 18:38:57

仅通过一个峰值的字符串将无法工作,该图还需要有关将这些字符串放在X轴上的信息。以下工作可以完成工作。

xticks!(p, xs, string.(xs))

将最后一个参数替换为tick所需的任何格式。

Passing only an iterable of strings would not work, the plot also needs information about where to place those strings on the x-axis. The following does the job.

xticks!(p, xs, string.(xs))

Replace the last argument with whatever formatting is required for the ticks.

梨涡少年 2025-01-29 18:38:57

您可能需要检查ControlSystems/plotting.jl(getLogticks)。
它似乎有使用科学符号的案例。以下使用壁虱数量来决定使用纯指数还是科学:

function getLogTicks(x, minmax)
    minx, maxx =  minmax
    major_minor_limit = 6
    minor_text_limit  = 8
    min               = minx <= 0 ? minimum(x) : ceil(log10(minx))
    max               = floor(log10(maxx))
    major             = exp10.(min:max)
    if Plots.backend() ∉ [Plots.GRBackend(), Plots.PlotlyBackend()]
        majorText = [latexstring("\$10^{$(round(Int64,i))}\$") for i = min:max]
    else
        majorText = ["10^{$(round(Int64,i))}" for i = min:max]
    end
    if max - min < major_minor_limit
        minor     = [j*exp10(i) for i = (min-1):(max+1) for j = 2:9]
        if Plots.backend() ∉ [Plots.GRBackend(), Plots.PlotlyBackend()]
            minorText = [latexstring("\$j\\cdot10^{$(round(Int64,i))}\$") for i = (min-1):(max+1) for j = 2:9]
        else
            minorText = ["$j*10^{$(round(Int64,i))}" for i = (min-1):(max+1) for j = 2:9]
        end

        ind       = findall(minx .<= minor .<= maxx)
        minor     = minor[ind]
        minorText = minorText[ind]
        if length(minor) > minor_text_limit
            minorText = [" " for t in minorText]#fill!(minorText, L" ")
        end
        perm = sortperm([major; minor])
        return [major; minor][perm], [majorText; minorText][perm]

    else
        return major, majorText
    end
end

You might want to check out ControlSystems/plotting.jl(getLogTicks).
It seems to have a case for using scientific notation. The following uses number of ticks to decide whether to use pure exponent or scientific:

function getLogTicks(x, minmax)
    minx, maxx =  minmax
    major_minor_limit = 6
    minor_text_limit  = 8
    min               = minx <= 0 ? minimum(x) : ceil(log10(minx))
    max               = floor(log10(maxx))
    major             = exp10.(min:max)
    if Plots.backend() ∉ [Plots.GRBackend(), Plots.PlotlyBackend()]
        majorText = [latexstring("\$10^{$(round(Int64,i))}\
quot;) for i = min:max]
    else
        majorText = ["10^{$(round(Int64,i))}" for i = min:max]
    end
    if max - min < major_minor_limit
        minor     = [j*exp10(i) for i = (min-1):(max+1) for j = 2:9]
        if Plots.backend() ∉ [Plots.GRBackend(), Plots.PlotlyBackend()]
            minorText = [latexstring("\$j\\cdot10^{$(round(Int64,i))}\
quot;) for i = (min-1):(max+1) for j = 2:9]
        else
            minorText = ["$j*10^{$(round(Int64,i))}" for i = (min-1):(max+1) for j = 2:9]
        end

        ind       = findall(minx .<= minor .<= maxx)
        minor     = minor[ind]
        minorText = minorText[ind]
        if length(minor) > minor_text_limit
            minorText = [" " for t in minorText]#fill!(minorText, L" ")
        end
        perm = sortperm([major; minor])
        return [major; minor][perm], [majorText; minorText][perm]

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