Tag Archives: julialang

Hungarian meeting with Euler for the third anniversary

By: Blog by Bogumił Kamiński

Re-posted from: https://bkamins.github.io/julialang/2023/05/05/hungarian.html

Introduction

I have been writing this blog for three years now, so I was
thinking what to post about to celebrate this.

Recently I have learned about the ProjectEuler.jl package.
I like it very much. It gives access to problems presented in
the Project Euler website in Julia REPL.
Additionally, when reading the documentation of the package it
mentioned a problem that I have not seen before. Therefore
I thought to solve it in this post.

This post was written under Julia 1.9.0-rc2, HiGHS v1.5.1,
Hungarian v0.7.0, JuMP v1.10.0, ProjectEuler v0.1.1.

The puzzle

Let us use ProjectEuler.jl to get the description of the
problem we want to solve:

julia> import ProjectEuler

julia> ProjectEuler.question(345)

│             Source: The following problem is taken from Project Euler
│      Problem Title: Problem 345: Matrix Sum
│       Published On: Saturday, 3rd September 2011, 04:00 pm
│          Solved By: 5813
│  Difficulty Rating: 15%

Problem
≡≡≡≡≡≡≡≡≡≡
We define the Matrix Sum of a matrix as the maximum possible sum of matrix
elements such that none of the selected elements share the same row or column.

For example, the Matrix Sum of the matrix below equals
3315 ( = 863 + 383 + 343 + 959 + 767):

                                                   7  53 183 439 863
                                                 497 383 563  79 973
                                                 287  63 343 169 583
                                                 627 343 773 959 943
                                                 767 473 103 699 303

Find the Matrix Sum of:

                         7  53 183 439 863 497 383 563  79 973 287  63 343 169 583
                       627 343 773 959 943 767 473 103 699 303 957 703 583 639 913
                       447 283 463  29  23 487 463 993 119 883 327 493 423 159 743
                       217 623   3 399 853 407 103 983  89 463 290 516 212 462 350
                       960 376 682 962 300 780 486 502 912 800 250 346 172 812 350
                       870 456 192 162 593 473 915  45 989 873 823 965 425 329 803
                       973 965 905 919 133 673 665 235 509 613 673 815 165 992 326
                       322 148 972 962 286 255 941 541 265 323 925 281 601  95 973
                       445 721  11 525 473  65 511 164 138 672  18 428 154 448 848
                       414 456 310 312 798 104 566 520 302 248 694 976 430 392 198
                       184 829 373 181 631 101 969 613 840 740 778 458 284 760 390
                       821 461 843 513  17 901 711 993 293 157 274  94 192 156 574
                        34 124   4 878 450 476 712 914 838 669 875 299 823 329 699
                       815 559 813 459 522 788 168 586 966 232 308 833 251 631 107
                       813 883 451 509 615  77 281 613 459 205 380 274 302  35 805

Manual solution

To start let us define the matrix that gives specification of the problem
and bind it to the M variable:

M = [  7  53 183 439 863 497 383 563  79 973 287  63 343 169 583
     627 343 773 959 943 767 473 103 699 303 957 703 583 639 913
     447 283 463  29  23 487 463 993 119 883 327 493 423 159 743
     217 623   3 399 853 407 103 983  89 463 290 516 212 462 350
     960 376 682 962 300 780 486 502 912 800 250 346 172 812 350
     870 456 192 162 593 473 915  45 989 873 823 965 425 329 803
     973 965 905 919 133 673 665 235 509 613 673 815 165 992 326
     322 148 972 962 286 255 941 541 265 323 925 281 601  95 973
     445 721  11 525 473  65 511 164 138 672  18 428 154 448 848
     414 456 310 312 798 104 566 520 302 248 694 976 430 392 198
     184 829 373 181 631 101 969 613 840 740 778 458 284 760 390
     821 461 843 513  17 901 711 993 293 157 274  94 192 156 574
      34 124   4 878 450 476 712 914 838 669 875 299 823 329 699
     815 559 813 459 522 788 168 586 966 232 308 833 251 631 107
     813 883 451 509 615  77 281 613 459 205 380 274 302  35 805]

Note that it is easy to do in Julia REPL, by copy-pasting the text
from the problem specification and just wrapping it with M = [ and ].

To solve the problem manually let us make the following observations:

  • Since every column has to be picked exactly once subtracting
    the same value from each element of some column does not affect the
    solution (the same holds for rows).
  • If in every row maximal element is in a different column then we can
    just pick these maximal elements in each row and these entries
    are the solution to our problem.

Using these two facts we will try to solve our problem. First let us
check if in our initial matrix M each row has a unique column where
it has a maximum value:

julia> findall(==(0), M .- maximum(M, dims=2))
15-element Vector{CartesianIndex{2}}:
 CartesianIndex(15, 2)
 CartesianIndex(2, 4)
 CartesianIndex(5, 4)
 CartesianIndex(11, 7)
 CartesianIndex(3, 8)
 CartesianIndex(4, 8)
 CartesianIndex(12, 8)
 CartesianIndex(13, 8)
 CartesianIndex(6, 9)
 CartesianIndex(14, 9)
 CartesianIndex(1, 10)
 CartesianIndex(10, 12)
 CartesianIndex(7, 14)
 CartesianIndex(8, 15)
 CartesianIndex(9, 15)

Unfortunately, this is not the case. We see that e.g. rows 2 and 5 have
maximum in column 4. Therefore we cannot trivially solve our problem.

However, let us try subtracting some values from columns of our
matrix M hoping that we will get the desired uniqueness.

The values we subtract from each column are:

julia> sub = [55 0 23 56 40 0 101 171 175 62 53 151 0 0 26]
1×15 Matrix{Int64}:
 55  0  23  56  40  0  101  171  175  62  53  151  0  0  26

Let us check them:

julia> M2 = M .- sub
15×15 Matrix{Int64}:
 -48   53  160  383  823  497  282   392  -96  911  234  -88  343  169  557
 572  343  750  903  903  767  372   -68  524  241  904  552  583  639  887
 392  283  440  -27  -17  487  362   822  -56  821  274  342  423  159  717
 162  623  -20  343  813  407    2   812  -86  401  237  365  212  462  324
 905  376  659  906  260  780  385   331  737  738  197  195  172  812  324
 815  456  169  106  553  473  814  -126  814  811  770  814  425  329  777
 918  965  882  863   93  673  564    64  334  551  620  664  165  992  300
 267  148  949  906  246  255  840   370   90  261  872  130  601   95  947
 390  721  -12  469  433   65  410    -7  -37  610  -35  277  154  448  822
 359  456  287  256  758  104  465   349  127  186  641  825  430  392  172
 129  829  350  125  591  101  868   442  665  678  725  307  284  760  364
 766  461  820  457  -23  901  610   822  118   95  221  -57  192  156  548
 -21  124  -19  822  410  476  611   743  663  607  822  148  823  329  673
 760  559  790  403  482  788   67   415  791  170  255  682  251  631   81
 758  883  428  453  575   77  180   442  284  143  327  123  302   35  779

julia> sol = findall(==(0), M2 .- maximum(M2, dims=2))
15-element Vector{CartesianIndex{2}}:
 CartesianIndex(6, 1)
 CartesianIndex(15, 2)
 CartesianIndex(8, 3)
 CartesianIndex(5, 4)
 CartesianIndex(4, 5)
 CartesianIndex(12, 6)
 CartesianIndex(11, 7)
 CartesianIndex(3, 8)
 CartesianIndex(14, 9)
 CartesianIndex(1, 10)
 CartesianIndex(2, 11)
 CartesianIndex(10, 12)
 CartesianIndex(13, 13)
 CartesianIndex(7, 14)
 CartesianIndex(9, 15)

Now we see that we have exactly one maximum value in each row and each of these values
is in a different column. Thus the solution to the problem can be calculated as
(I do not show the solution to encourage you to try solving the problem yourself):

sum(M[sol])

Now you might ask how one could get the sub vector?
You could find it by trial and error, or use a more systematic way.
Interestingly the problem we solve today is an important question
in operations research, and a specialized algorithm was developed to solve it.

Hungarian solution

The algorithm that can be used to solve this class of problems is called
Hungarian algorithm. It is implemented in Julia in the Hungarian.jl
package. I encourage you to study it, however, let me just mention that it uses
a refined version of the two observations we have made when developing the manual
solution.

The package is easy to use. You just need to remember that by default it minimizes
the sum, so we need to use the -M matrix. Here is how you can get
the solution (I show you the indices, but drop displaying the value of the solution):

julia> using Hungarian

julia> hungarian(-M)[1]
15-element Vector{Int64}:
 10
 11
  8
  5
  4
  1
 14
  3
 15
 12
  7
  6
 13
  9
  2

You might ask how we could check if our manual solution and the solution obtained
using the package match. You can do it as follows:

julia> getindex.(sol, 1) == hungarian(-M')[1]
true

All matches as expected.

Note that for the check I used the hungarian function with the transposition
of the M matrix as our cartesian indices are sorted by column number
(the reason is that Julia uses column major storage order) and by default
hungarian returns column indices sorted by row number.

Solver solution

What if we did not have the Hungarian.jl package?
In this case the problem can be solved using mixed integer programming.
I have decided to use the JuMP.jl and HiGHS.jl packages to get the answer
(as usual – the value of the solution is not shown):

using JuMP
import HiGHS
model = Model(HiGHS.Optimizer)
@variable(model, x[1:15, 1:15], Bin)
for i in 1:15
    @constraint(model, sum(x[i, j] for j in 1:15) == 1)
    @constraint(model, sum(x[j, i] for j in 1:15) == 1)
end
@objective(model, Max, sum(x[i, j] * M[i, j] for i in 1:15, j in 1:15))
optimize!(model)
value.(x)

I really enjoy using the JuMP.jl API for solving optimization problems.

As above let us check if the solution matches the solution we obtained manually:

julia> findall(>=(0.5), value.(x)) == sol
true

Note that I use 0.5 to separate 0 from 1 solutions as this is a
safe boundary value even if there were some numerical inaccuracies in the
returned solution.

Conclusions

I really enjoy solving Project Euler puzzles using Julia.
The syntax and package ecosystem that I have at hand make it
quite convenient. The resulting codes are usually short and easy to read.

If you liked the problem let me give you a challenge. Notice that
the sum of values we subtracted in the manual solution was:

julia> sum(sub)
913

The challenge for you is to find such non-negative entries of sub
that uniquely solve our problem (in the manual approach) and
minimize the sum of entries of sub. I hope you will enjoy solving
this extra puzzle!

Ref ref.

By: Blog by Bogumił Kamiński

Re-posted from: https://bkamins.github.io/julialang/2023/04/28/ref.html

Introduction

Today I want to discuss the Ref type defined in Base Julia.
The reason is that it is often used in practice, but it is not immediately
obvious what the design behind Ref is.

I will focus on an entry-level introduction to the topic and leave out
more advanced issues that are typically not needed when working with
Julia.

This post is written under Julia 1.9.0-rc2.

Where can you see Ref?

As a normal Julia user there are two cases, where you might encounter Ref:
broadcasting and allowing mutation.

Broadcasting

The first case is in broadcasting when you want to store some object in a
0-dimensional container that protects its contents from being broadcasted over.
Here is a typical example:

julia> x = [1, 2, 3]
3-element Vector{Int64}:
 1
 2
 3

julia> y = [2, 3, 4]
3-element Vector{Int64}:
 2
 3
 4

julia> Ref(x) .* y
3-element Vector{Vector{Int64}}:
 [2, 4, 6]
 [3, 6, 9]
 [4, 8, 12]

Note that I wrap x in Ref to ensure that the whole x vector is multiplied
by elements of y. If I omitted Ref I would get an elementwise product of
x and y:

julia> x .* y
3-element Vector{Int64}:
  2
  6
 12

The reason why Ref is used in such cases is that Ref makes a minimal impact on
the type of the result of the broadcasted operation. Consider this example:

julia> z = (2, 3, 4)
(2, 3, 4)

julia> [x] .* z
3-element Vector{Vector{Int64}}:
 [2, 4, 6]
 [3, 6, 9]
 [4, 8, 12]

julia> Ref(x) .* z
([2, 4, 6], [3, 6, 9], [4, 8, 12])

Here I protected x when multiplying it by elements of the tuple z.
I could protect x by wrapping it with a vector, but, as you can see
then the result of the operation would be vector of vectors. While
wrapping x in Ref produces a tuple of vectors as a result.
As you can see, using Ref made broadcasting mechanism use the type of
the other container to determine the output type, which is typically desirable.

Allowing mutation

The other use of Ref is when we have an immutable type that we want to be able
to mutate ?. This might sound strange, but sometimes indeed it is useful.

Let me give you a simple example:

julia> struct X
           value::Int
           callcount::Base.RefValue{Int}

           X(x) = new(Int(x), Ref(0))
       end

julia> f(x::X) = (x.callcount[] += 1; x)
f (generic function with 1 method)

julia> x = X(10)
X(10, Base.RefValue{Int64}(0))

julia> f(x)
X(10, Base.RefValue{Int64}(1))

julia> f(x)
X(10, Base.RefValue{Int64}(2))

julia> f(x)
X(10, Base.RefValue{Int64}(3))

Here I defined the X type that stores a value, which I want to be immutable,
and an extra field callcount that counts how many times the function f was
called on this object. Since Int is immutable, I needed to wrap it with Ref
to achieve the mutability of this field.

As a side note this is not the only way to get this kind of effect. For example,
I could define a mutable struct with const field value. Still in some
cases Ref is a useful because it is mutable. Note that I accessed and updated
the value stored in Ref using empty indexing x.callcount[] (i.e. brackets
with no value inside them).

So what is hard about Ref?

In the last example I said I am talking about Ref, but in the definition of
the X type I used callcount::Base.RefValue{Int} instead. This is the tricky
part. Ref is a parametric abstract type. This means that no object can have
Ref type. Ref is a non-leaf node in the type tree in Julia. Let us check its
subtypes:

julia> subtypes(Ref)
6-element Vector{Any}:
 Base.CFunction
 Base.RefArray
 Base.RefValue
 Core.Compiler.RefValue
 Core.LLVMPtr
 Ptr

As you can see there are six types that are subtypes of Ref. And here comes
why I have said that I want our post today to be entry-level. I will only talk
about RefValue and RefArray. I leave out other options as they are
rarely needed (unless you are doing low-level stuff in Julia, but then probably
you do not need to read this post ?).

The tricky thing is that when we write Ref(1) we do not get an object
whose type is Ref, but instead a RefValue (that is a subtype of Ref):

julia> v1 = Ref(1)
Base.RefValue{Int64}(1)

julia> v1[]
1

Similarly we can have a reference to an element of an array. In this case
we pass an array as a first argument to Ref and an index as a second one:

julia> v2 = Ref([2, 3, 4], 2)
Base.RefArray{Int64, Vector{Int64}, Nothing}([2, 3, 4], 2, nothing)

julia> v2[]
3

You can think of Ref as a convenient way to handle both cases (wrapping a value
and wrapping an element of an array) in a single syntax.

There is one difference between RefValue and RefArray though. RefValue
indeed guarantees mutability of the container as we have seen in the example
above with the X struct. Trying to mutate RefArray will try to mutate
the underlying array. Therefore the following code fails:

julia> v3 = Ref(2:4, 2)
Base.RefArray{Int64, UnitRange{Int64}, Nothing}(2:4, 2, nothing)

julia> v3[] = 10
ERROR: CanonicalIndexError: setindex! not defined for UnitRange{Int64}

While this code works:

julia> a = [2, 3, 4]
3-element Vector{Int64}:
 2
 3
 4

julia> v4 = Ref(a, 2)
Base.RefArray{Int64, Vector{Int64}, Nothing}([2, 3, 4], 2, nothing)

julia> v4[]
3

julia> v4[] = 100
100

julia> v4
Base.RefArray{Int64, Vector{Int64}, Nothing}([2, 100, 4], 2, nothing)

julia> a
3-element Vector{Int64}:
   2
 100
   4

and we can see that the a array was changed.

Conclusions

The major things to remember about Ref are:

  • Its main uses are in broadcasting and when we need a lightweight mutable container.
  • Ref is abstract, when you write Ref(x) you do not get a Ref instance. Instead
    you will get a RefValue (which is mutable).
  • There are other subtypes of Ref than just RefValue. You will rarely need them.
    Of the other options the one you might want to use most often is RefArray, which
    creates a reference to a single element of the underlying array.

I hope you found this post a useful ref. for Ref.

MakieCon 2023 was amazing!

By: Blog by Bogumił Kamiński

Re-posted from: https://bkamins.github.io/julialang/2023/04/21/aog.html

Introduction

This week I participated in MakieCon 2023.
The conference was devoted to Makie, which is a data visualization
ecosystem for the Julia programming language, with high performance and extensibility.

The things you already can do with Makie are mind blowing,
including 2D and 3D plots, animations, dashboards and more.
If you want to see some showcases check out the Beautiful Makie website.

Today I want to write about AlgebraOfGraphics.jl package defines
a language for data visualization, that is especially useful with tabular data.

It is natural to compare AlgebraOfGraphics.jl to ggplot2 as indeed both
ecosystems allow to declaratively create graphics. In this post I want to highlight
one important difference. The ggplot2 is designed to be a stand alone ecosystem.
While AlgebraOfGraphics.jl is an addition to Makie.jl that makes standard tabular data
visualization easy. However, you still can apply all low-level operations that Makie.jl
provides to the created plots. Therefore you get the best of both worlds:

  • a convenient declarative system for defining plots;
  • ability of easy modification of generated plots to tune them to the exact needs of a data scientist.

I want to show you how this is achieved by example.

The post was written under Julia 1.9.0-rc1, AlgebraOfGraphics v0.6.14,
CSV v0.10.9, CairoMakie v0.10.4, and DataFrames v1.5.0.

Setting up the scene

We will want to plot the following data stored in CSV format:

aog_csv = """
problem,language,time,size
binary-trees,Java,1.5886075949367087,1.0321384425216316
binary-trees,Julia,4.6075949367088604,0.7836835599505563
binary-trees,Python,28.29113924050633,0.8158220024721878
fannkuch-redux,Java,1.3825857519788918,1.408791208791209
fannkuch-redux,Julia,1.0329815303430079,1.1725274725274726
fannkuch-redux,Python,45.04617414248021,1.043956043956044
fasta,Java,1.5384615384615383,1.7382091592617908
fasta,Julia,1.4487179487179485,0.7395762132604238
fasta,Python,47.30769230769231,1.330827067669173
k-nucleotide,Java,1.2196969696969697,1.203187250996016
k-nucleotide,Julia,1.2474747474747476,0.6314741035856574
k-nucleotide,Python,11.694444444444445,1.3061088977423638
mandelbrot,Java,3.1538461538461533,0.7013215859030837
mandelbrot,Julia,1.0923076923076922,0.5453744493392071
mandelbrot,Python,136.4230769230769,0.6061674008810573
n-body,Java,3.1784037558685445,0.9118187385180649
n-body,Julia,1.9765258215962442,0.6803429271279853
n-body,Python,254.15023474178406,0.7323943661971831
pidigits,Java,1.4107142857142856,0.7009174311926606
pidigits,Julia,1.732142857142857,0.46422018348623856
pidigits,Python,2.071428571428571,0.5201834862385321
regex-redux,Java,6.675,0.6649964209019327
regex-redux,Julia,2.175,0.5433070866141733
regex-redux,Python,1.675,1.0042949176807445
reverse-complement,Java,3.829268292682927,1.110941475826972
reverse-complement,Julia,3.5121951219512195,0.26564885496183205
reverse-complement,Python,16.146341463414636,0.41424936386768446
spectral norm,Java,3.780487804878049,0.631578947368421
spectral norm,Julia,2.707317073170732,0.3583959899749373
spectral norm,Python,275.5365853658537,0.34001670843776105
"""

The CSV stores information on speed and code size of programs
written in Java, Julia, and Python relative to C for ten selected
computational problems. The data was taken from
The Computer Language Benchmarks Game website.
I discuss the interpretation of this data in Chapter 1 of Julia for Data Analysis book.

Let us first load this data to a data frame:

using AlgebraOfGraphics
using CairoMakie
using CSV
using DataFrames
aog_df = CSV.read(IOBuffer(aog_csv), DataFrame)

You should get the following output:

30×4 DataFrame
 Row │ problem             language  time       size
     │ String31            String7   Float64    Float64
─────┼───────────────────────────────────────────────────
   1 │ binary-trees        Java        1.58861  1.03214
   2 │ binary-trees        Julia       4.60759  0.783684
   3 │ binary-trees        Python     28.2911   0.815822
   4 │ fannkuch-redux      Java        1.38259  1.40879
   5 │ fannkuch-redux      Julia       1.03298  1.17253
   6 │ fannkuch-redux      Python     45.0462   1.04396
   7 │ fasta               Java        1.53846  1.73821
   8 │ fasta               Julia       1.44872  0.739576
   9 │ fasta               Python     47.3077   1.33083
  10 │ k-nucleotide        Java        1.2197   1.20319
  11 │ k-nucleotide        Julia       1.24747  0.631474
  12 │ k-nucleotide        Python     11.6944   1.30611
  13 │ mandelbrot          Java        3.15385  0.701322
  14 │ mandelbrot          Julia       1.09231  0.545374
  15 │ mandelbrot          Python    136.423    0.606167
  16 │ n-body              Java        3.1784   0.911819
  17 │ n-body              Julia       1.97653  0.680343
  18 │ n-body              Python    254.15     0.732394
  19 │ pidigits            Java        1.41071  0.700917
  20 │ pidigits            Julia       1.73214  0.46422
  21 │ pidigits            Python      2.07143  0.520183
  22 │ regex-redux         Java        6.675    0.664996
  23 │ regex-redux         Julia       2.175    0.543307
  24 │ regex-redux         Python      1.675    1.00429
  25 │ reverse-complement  Java        3.82927  1.11094
  26 │ reverse-complement  Julia       3.5122   0.265649
  27 │ reverse-complement  Python     16.1463   0.414249
  28 │ spectral norm       Java        3.78049  0.631579
  29 │ spectral norm       Julia       2.70732  0.358396
  30 │ spectral norm       Python    275.537    0.340017

Drawing a plot

Start with a complete code producing the plot:

fig = Figure(resolution = (900, 600))
aog_plt = data(aog_df) *
          mapping(:problem, [:time, :size];
                  marker=:language,
                  color=:language,
                  col = dims(1) => renamer(["", ""])) *
          visual(Scatter; markersize=15, strokewidth=1)
grid = draw!(fig, aog_plt,
             axis=(; xticklabelrotation=pi/6),
             palettes=(; marker=[:rect, :circle, :diamond],
                       color=["lightgray", "gold", "lightblue"]))
grid[1].axis.yscale = log10
hlines!(grid[1].axis, 1.0; color="red")
hlines!(grid[2].axis, 1.0; color="red")
lg = AlgebraOfGraphics.compute_legend(grid)
push!(lg[1][1], [LineElement(color="red")])
push!(lg[2][1], "C")
Legend(fig[1, end+1], lg...)
fig

It produces the following figure:

Benchmark

On the figure we can see that Julia performs quite well in both
time and code size in comparison to other programming languages.

However, today I want to focus on plotting.

The first thing is displaying the plot.
If you use Jupyter Notebook or VS Code the plot will be just shown.
However, if you work in the terminal automatic displaying is turned
off by default. You need to run the Makie.inline!(false) command
to turn it on. After issuing it each time you try to display the
figure it will be opened in your default image viewer.

Now let me comment on the plotting code.
If you have never used AlgebraOfGraphics.jl I recommend you first
read the AlgebraOfGraphics.jl manual as the code
I used is relatively advanced.

The line creating the aog_plt object is using AlgebraOfGraphics.jl
commands. As you can see using * we can link data, with mapping operations
and visualization commands. What is interesting in the presented case
is the fact that my source data contains two columns :time and :size
that I want plotted on separate subplots. This is not a problem in
AlgebraOfGraphics.jl. I just needed to pass a vector [:time, :size]
to make it work. Later the col = dims(1) => renamer(["", ""]) instruction
signals that I want to have them plotted in separate subplots. The
renamer(["", ""]) disables display of subplot titles as I have
series names shown as y-axis labels anyway.

Now notice the draw! command. It inserts the plot specification
created in AlgebraOfGraphics.jl into a Makie figure. The nice thing is
that it is possible to customize the plot by passing axis and palettes
keyword arguments.

The code that was really interesting for me comes next. The grid variable
is bound to a standard Makie object. Therefore I can later tweak as I wish
using Makie primitives. In this case what I wanted to do was:

  • Changing the y-axis of the first of the plots to logarithmic scale.
    I could easily achieve this by writing grid[1].axis.yscale = log10.
  • Adding two custom horizontal lines (representing the reference C language)
    to both plots which I achieved using the hline! command.
  • Manually adding the C language entry to the legend of the plot which
    I achieved by manipulating the lg object.

What is important is that even for someone who is not a Makie expert it was possible to
work out how the underlying objects should be mutated to get what I wanted
without a significant effort.

Of course one might want AlgebraOfGraphics.jl to be a complete plotting
system like ggplot2. However, I think that the choice made in it is correct.
I appreciate that the API of AlgebraOfGraphics.jl is relatively small.
In this way you can easily learn to do simple and standard things.
It also means that is is convenient to do exploratory data analysis
(when you often need to do a lot of simple plots).
Later, if I am to prepare a publication quality plot in which I need to perform
some non-standard customizations I can use the Makie functionality
to achieve this.

Conclusions

Here are the key things I learned during MakieCon 2023:

  • Makie ecosystem provides a lot of advanced functionalities that
    are hard to find in other plotting packages. I typically need to prepare
    high-quality plots for publications. In this aspect a particular value
    of Makie is that it allows you to tweak every detail of the plot
    the way you want.
  • AlgebraOfGraphics.jl is not an equivalent of ggplot2
    (which is a complete stand-alone plotting system). I find it easier
    to think about AlgebraOfGraphics.jl as a set of extra functions that build on top
    of Makie and provide a convenient way to create visualizations of tabular data.
    However, you can later fall-back to Makie primitives to further customize the plots if needed.

Additionally, if you want to start working with Makie ecosystem you need to know that:

  • It is essential that you read the Makie tutorial first.
    To ensure the full flexibility of how your plots are styled Makie.jl introduces
    several concepts (like Figure or Axis objects) that you need to learn if you
    want to confidently work with it.
  • Makie ecosystem provides several plotting backends that differ in functionality.
    I use CairoMakie.jl as I typically need non-interactive 2D plots that have
    publication quality. As a particular thing in this case you need to know
    that if you are working in a terminal you need to use the Makie.inline!(false)
    command to turn-on automatic rendering of a plot (this is not needed in Jupyter Notebook
    and VS Code) if you want it (alternatively you can explicitly save your plot
    to a file).

Before I finish I would like to thank Dr. Lazaro Alonso Silva for inviting me to the event.
The conference was an exceptional experience. Makie community is amazing and full of brilliant members.

I also appreciate a lot the help from Pietro Vertechi and Fabian Greimel
that gave me many useful hints about how to get the most out of AlgebraOfGraphics.jl.