简体   繁体   English

如何修改 Julia 中的上标(Gadfly 图的标签)?

[英]How to modify superscripts in Julia (labels of Gadfly plots)?

Could somebody suggest me how to initiate and end the superscript in a Gadfly plot using Julia correctly?有人可以建议我如何正确使用JuliaGadfly plot 中启动和结束上标吗? Or if there are any other better solutions instead of using <sup></sup> , please also share them with me.或者如果有任何其他更好的解决方案而不是使用<sup></sup> ,也请与我分享。 Thanks so much.非常感谢。

using Gadfly
ticks = [400, 1000, 1500, 2000, 2500, 3000, 3500, 4000]
Gadfly.plot(PET, x = :Wavenumber, y = :Transmittance, Geom.line, 
            Coord.cartesian(xflip=true, xmin=400, xmax=4000, ymax=100, ymin=0),
            Scale.x_continuous(maxticks=2000), 
            Guide.xticks(ticks=ticks),
            Guide.xlabel("Wavenumber (cm<sup>-1</sup>)"),
            Guide.ylabel("Transmittance (%)"))

在此处输入图像描述

  1. In a supported text editor, you can type the superscript characters directly with tab completion.在支持的文本编辑器中,您可以使用制表符完成直接键入上标字符。 \^-1<Tab> should transform into ⁻¹ once you press <Tab> . \^-1<Tab>应在您按下<Tab>后转换为⁻¹
  2. Copy the characters from this answer to your string: ⁻¹ .将此答案中的字符复制到您的字符串: ⁻¹
  3. Use my function below to convert integers to their corresponding Unicode superscripts.使用我下面的 function 将整数转换为相应的 Unicode 上标。 Use the * function to join the output string with the rest of your xlabel .使用* function 将 output 字符串与 xlabel 的xlabel
"Finds and prints the appropraite unicode value for any numerical superscript."
function superscriptnumber(i::Int)
    if i < 0
        c = [Char(0x207B)]
    else
        c = []
    end
    for d in reverse(digits(abs(i)))
        if d == 0 push!(c, Char(0x2070)) end
        if d == 1 push!(c, Char(0x00B9)) end
        if d == 2 push!(c, Char(0x00B2)) end
        if d == 3 push!(c, Char(0x00B3)) end
        if d > 3 push!(c, Char(0x2070+d)) end
    end
    return join(c)
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM