Any package for plots in style of Scientific Journals?

Hi again folks, now I’m stumped on getting a stacked bar graph (after several attempts). I had one in the regular Plots package, does anyone know how to translate the following (successful code) into Makie:

MyBarGraphPlot = groupedbar(
  [DataArray1 DataArray2],
  bar_position = :stack,
  bar_width=0.5,
  xlabel = "x", ylabel = "y",
  label=["DataSet1" "DataSet2"],
);
display(MyBarGraphPlot)

Thank you!

See several examples in this section of the Makie documentation.

1 Like

# Fake data
categories = 1:6
DataArray1 = [4.0, 7.0, 3.0, 8.0, 5.0, 6.0]
DataArray2 = [3.0, 2.0, 5.0, 4.0, 6.0, 3.0]

fig = Figure()
ax = Axis(fig[1, 1], xlabel = "x", ylabel = "y")

# Stacked bars: DataSet1 on bottom, DataSet2 on top
barplot!(ax, categories, DataArray1,
    label = "DataSet1", color = :steelblue, width = 0.5)
barplot!(ax, categories, DataArray2,
    offset = DataArray1, label = "DataSet2", color = :orange, width = 0.5)

axislegend(ax)

fig

2 Likes

Thanks technocrat,that works very well!
The only issue is that the marker titles are overlapping each other:

I’m trying commands like this, but no fix found yet:

axislegend(ax, position = :rt, framevisible = true, patchsize = (9, 15), patchlabelgap = 1.0)

(Also tried padding, didn’t help.)

Note that I am wrapping my barplot in:
with_theme(theme_aps(), figure_padding = (4, 4, 4, 4)) do block.

This is why there are multiple plotting packages in Julia. They cater for different needs and have different philosophies. The Makie package is inspired I think a lot by matplotlib. It is very powerful, creates beautiful results and gives you a high degree of control, but the syntax is somewhat cumbersome. I personally do not use Makie for this reason, unless I have a very specific use case. The Plots package is very different - it is narrowly focused on making it easy and seamless for users to create plots, at the cost of somewhat less customisability and control.

1 Like

Try adding labelsize to set the font size smaller. The trick getting a happy medium between plain makie defaults and using a theme setup such as this is to pick a spot in the continuum and use that consistently or you’ll find yourself asking if it wouldn’t. be better to save to svg and do the microtuning in a vector editor.

1 Like

Thanks again, labelsize did fix the words in the barplot legend! But, the legend marker boxes still stick together & are too big. I could not fix it with markersize, labelsize, patchsize, or patchlabelgap. Here is an example of the code (modified from your example) & results:

# Fake data
categories = 1:6
DataArray1 = [4.0, 7.0, 3.0, 8.0, 2.0, 1.0]
DataArray2 = [3.0, 2.0, 5.0, 4.0, 1.0, 2.0]
#
with_theme(theme_aps(), figure_padding = (4, 4, 4, 4)) do 
    #
    fig = Figure()
    ax = Axis(fig[1, 1], xlabel = "x", ylabel = "y")
    #
    # Stacked bars: DataSet1 on bottom, DataSet2 on top
    Makie.barplot!(ax, categories, DataArray1, width = 0.5,
        label = "DataSet1" => (; markersize = 4, strokecolor = :black, strokewidth = 0.5))
    Makie.barplot!(ax, categories, DataArray2, offset = DataArray1, width = 0.5,
        label = "DataSet2" => (; markersize = 4, strokecolor = :black, strokewidth = 0.5))
    #
    ### Makie.axislegend(ax, position = :rt, framevisible = true, patchsize = (9, 15), patchlabelgap = 1.0)
    Makie.axislegend(ax, position = :rt, framevisible = true, labelsize = 8.25,
        padding = (-4.0, 2.5, -2.0, -2.0), patchsize = (9, 20), patchlabelgap = 2.0)
#
fig
#
end

Hopefully there is some parameter which can adjust this, because the “microtuning in a vector editor” sounds like an awful task (with a brand new learning curve). Thanks!

Did you try to add two labels and remove the current text?

There should be a way to position text freely in Makie. I used code like this, for example:

    label3 = Label(fig, "time_lapse", bbox=fig.scene.viewport)
    label3.halign[]=:left
    label3.valign[]=:top
    label3.alignmode=Outside(160, 0, 0, 100)

If you add two labels, you should be able to position them freely.

1 Like

I did not try that, it sounds clever, but I do not know how to put two different axislegend commands into a single with_theme do block. Do you think you could integrate your idea into the sample code I included in my previous message? Thanks!

Try

Makie.axislegend(ax, position = :rt, framevisible = true, labelsize = 8.25,
padding = (-4.0, 2.5, -2.0, -2.0), patchsize = (9, 20), patchlabelgap = 2.0,
patchstrokewidth = 0)
This follows Tufte’s principle that every pixel should contribute something, in this case to make the legend useful. Right now the boxes are superficial decoration—you can “see” both the colors and their labels without them.

Oddly, patchstrokewidth doesn’t seem to do anything at all, whether its there or not there, set to zero or any other value.

The boxes in the legend seem to be controlled by the label = "DataSet1" => (; etc., strokewidth = 0.5)) options in the barplot! command, and changing or getting rid of those lines doesn’t fix the size-of-the-colorful-rectangles problem.

1 Like

Apologies, I was too lazy to load the themes package. This should be the last in this thread because good hygiene limits the number of “post-solution” replies. Just link to the previous thread for context.

using CairoMakie
# Fake data
categories = 1:6
DataArray1 = [4.0, 7.0, 3.0, 8.0, 5.0, 6.0]
DataArray2 = [3.0, 2.0, 5.0, 4.0, 6.0, 3.0]

fig = Figure()
ax = Axis(fig[1, 1], xlabel = "x", ylabel = "y")
barplot!(ax, categories, DataArray1,
    label = "DataSet1", color = :steelblue, width = 0.5)
barplot!(ax, categories, DataArray2,
    offset = DataArray1, label = "DataSet2", color = :orange, width = 0.5)
axislegend(ax; framevisible = false)

fig

Ok then… just, this solution still does not work in the with_theme(theme_aps()) do wrapper.
So I don’t have a solution yet. I guess I’ll start a new thread for this, or make do with what I have.

You do not need two axislegend calls. Just legend.