【问题标题】:Julia: PlotlyJS and relative bar subplotsJulia:PlotlyJS 和相关条形图
【发布时间】:2018-01-28 01:39:42
【问题描述】:

我最近开始使用 PlotlyJS。

我正在尝试创建相对条形图的子图(barmode=relative 的条形图)。不幸的是,当条形图成为子图时,它们似乎失去了 barmode 属性。例如:

# PlotlyJS
using PlotlyJS;
pltjs = PlotlyJS

function bar1()
    trace1 = pltjs.bar(;x=[1, 2, 3, 4], y=[1, 4, 9, 16], name="Trace1")
    trace2 = pltjs.bar(;x=[1, 2, 3, 4], y=[6, -8, -4.5, 8], name="Trace2")
    data   = [trace1, trace2];

    layout = pltjs.Layout(;xaxis_title="X axis",
                           yaxis_title="Y axis",
                           barmode="relative",
                           title="Relative 1");
    pltjs.plot(data, layout)
end


function bar2()
    trace3 = pltjs.bar(;x=[1, 2, 3, 4], y=[-15, -3, 4.5, -8], name="Trace3")
    trace4 = pltjs.bar(;x=[1, 2, 3, 4], y=[-1, 3, -3, -4], name="Trace4")
    data   = [trace3, trace4];

    layout = pltjs.Layout(;xaxis_title="X axis",
                           yaxis_title="Y axis",
                           barmode="relative",
                           title="Relative 2");
    pltjs.plot(data, layout)
end

p1 = bar1();
pltjs.savefig(p1, "./fig1.pdf") # This works

p2 = bar2();
pltjs.savefig(p2, "./fig2.pdf") # This works

p3 = [bar1() bar2()];
pltjs.savefig(p3, "./fig3.pdf") # This doesn't works

我在其他语言中看到过类似的问题,但我无法为 Julia 找到解决方法。请您解释一下为什么不起作用以及如何解决?

【问题讨论】:

    标签: charts julia plotly


    【解决方案1】:

    我设法使用下面的代码做到了:

    p3.plot.layout["barmode"] = "relative";
    

    【讨论】:

      猜你喜欢
      • 2018-07-15
      • 1970-01-01
      • 2021-12-23
      • 2023-04-06
      • 1970-01-01
      • 2014-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多