Reputation: 945
I have recently started using PlotlyJS.
I am trying to create a subplots of relative bar charts (bar charts with barmode=relative). Unfortunately it seems that the bar charts lose their barmode attribute, when they become a subplot. For example:
# 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
I have seen similar issues in other languages, but I wasn't able to find a workaround for Julia. Would you please explain me why doesn't work and how to fix it?
Upvotes: 0
Views: 342
Reputation: 945
I managed to do it using the code below:
p3.plot.layout["barmode"] = "relative";
Upvotes: 1