Skip to content

Makie.jl plotting extension, deprecate Plots.jl recipes - #428

Merged
lkdvos merged 6 commits into
mainfrom
bd/plotting
Nov 5, 2026
Merged

lkdvos merged 6 commits into
mainfrom
bd/plotting

Conversation

@borisdevos

@borisdevos borisdevos commented May 20, 2026 •

Copy link
Copy Markdown
Member

Deals with #249: Makie.jl support for the entanglement and transfer spectrum plots, and deprecation of the Plots.jl recipes.

Makie: entanglement_plot and transfer_plot

MPSKitMakieExt is loaded with any Makie backend (e.g. using CairoMakie). It provides entanglement_plot, transfer_plot and their mutating ! versions as ordinary Makie recipes, following Makie's guidance for recipes in package extensions:

  • The function stubs live in MPSKit and the extension adds the recipe methods to them.
  • Axis defaults (titles, labels, sector ticks, log scale) come from Makie.preferred_axis_attributes instead of editing the current axis. Override them with Makie's usual axis = (; title = "...").
  • ! calls leave the target axis alone unless use_axis_hints = true is passed.
  • Each sector is a labelled scatter, so axislegend(ax) lists the sectors.
  • Vanishing Schmidt values are left out of the entanglement plot, with a warning.
using MPSKit, CairoMakie
entanglement_plot(ψ; expand_symmetry = true, axis = (; title = "ψ"))
fig, ax, _ = transfer_plot(ψ; sectors = [Z2Irrep(0), Z2Irrep(1)], transferkwargs = (; howmany = 5))
axislegend(ax)

Plots: deprecated

The Plots.jl recipes entanglementplot and transferplot now live in MPSKitPlotsExt, with RecipesBase as a weak dependency, and print a deprecation warning. They keep their previous behaviour. The Makie functions have different names, so both backends can be loaded in one session; previously each extension silently overwrote the other's methods, depending on load order.

Other changes

  • The data preparation for both plots lives in MPSKit (MPSKit.entanglement_plot_data, MPSKit.transfer_plot_data, unexported), so the two extensions only handle drawing and styling.
  • Fix the angle shift for a nonzero thetaorigin in the transfer spectrum, which moved eigenvalues outside the plotted range (both backends).
  • All examples now use CairoMakie; Plots is dropped from the examples and docs environments, and every example page is regenerated.
  • examples/figure_externalization.jl also accepts Makie's base64, data URIs, so figures are written to files instead of being embedded in the page.

Note on history

The branch was squashed onto main (author kept as @borisdevos). The :axis_info-node rework from 2026-09-18 is superseded by the preferred_axis_attributes approach above; its vanishing-Schmidt-value warning has been carried over. The previous history is kept locally on bd/plotting-backup.

🤖 Generated with Claude Code

@lkdvos lkdvos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely looks great!
I have a couple questions, mostly since it has been a while since I looked at Makie:

Do you know if the other attributes can still be set/changed? For example, what happens if I want to override the default title/ticks/...?

I seem to recall also that there was some system with observables etc, where various parts where dynamically recalculated. Do you know if this is still relevant?

Comment thread test/Project.toml Resolved
Comment thread Project.toml Resolved
@borisdevos

Copy link
Copy Markdown
Member Author
entspec_makie_plotkwargs transpec_makie_plotkwargs

I just tried some random keyword arguments for the Makie plots, and they seem to work. I'll test tomorrow if I can do the same for Plots.
(Also I realised I was running Z2-symmetric MPS in the Z2 SSB phase 🫠)

@borisdevos

Copy link
Copy Markdown
Member Author

I don't understand the current aqua test failing. It seems to be complaining about missing compat bounds for every package under extras of the main project.toml (but are specified in the test project.toml), but this previously wasn't failing.

Comment thread Project.toml Resolved
@codecov

codecov Bot commented May 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.49550% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ext/MPSKitPlotsExt.jl 93.61% 3 Missing ⚠️
ext/MPSKitMakieExt.jl 95.34% 2 Missing ⚠️
Files with missing lines Coverage Δ
src/MPSKit.jl 100.00% <ø> (ø)
src/utility/plotting.jl 100.00% <100.00%> (+17.64%) ⬆️
ext/MPSKitMakieExt.jl 95.34% <95.34%> (ø)
ext/MPSKitPlotsExt.jl 93.61% <93.61%> (ø)

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@borisdevos

Copy link
Copy Markdown
Member Author

Okay, I finally managed to look into this again. I'm happy with how things are in terms of being able to use these backends with some customisation. What remains is some stylistic decisions. In particular, I don't know how useful it is to plot transfer matrix spectra the way we are now. These phases don't matter in many cases, so if we allow some toggle to not plot them, there's then a way to plot the different sectors next to each other, similar to the current entanglement plots.

Some other style choices are in todos, though I'm sure there are many more.

Comment thread test/runtests.jl Resolved
Comment thread Project.toml Resolved
Comment thread ext/MPSKitMakieExt.jl Resolved
Comment thread ext/MPSKitMakieExt.jl Resolved
Comment thread ext/MPSKitMakieExt.jl Resolved
Comment thread ext/MPSKitMakieExt.jl Resolved
borisdevos and others added 5 commits November 3, 2026 11:19
- `entanglement_plot(!)` and `transfer_plot(!)`: Makie recipes in a new
  `MPSKitMakieExt`, extending stubs defined in MPSKit. Axis defaults come from
  `preferred_axis_attributes` (overridable through `axis = (; ...)`), mutating
  calls leave the target axis untouched unless `use_axis_hints = true`, and
  `axislegend(ax)` lists the sectors.
- `entanglementplot` and `transferplot` move to `MPSKitPlotsExt` with RecipesBase
  as a weak dependency, and are deprecated. Distinct names keep both backends
  usable in one session.
- Fix the angle shift for a nonzero `thetaorigin`.

Squashed from bd/plotting (#428).

Co-Authored-By: lkdvos <ldevos98@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use `entanglement_plot`/`transfer_plot` with CairoMakie in the xxz-heisenberg and
haldane-spt examples, and regenerate their pages. Makie embeds figures as
`base64, <data>`, so the figure externalization now allows whitespace after the comma.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The weakdep compat in the main Project.toml already bounds Makie, and the tests
reach it through CairoMakie.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…plot

Carried over from 0418d74 on the previous branch history.

Co-Authored-By: lkdvos <ldevos98@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drop Plots (and LaTeXStrings) from the examples and docs environments, port the
remaining examples' figures to Makie, and regenerate every example page.
`make.jl` now resets the Makie theme between examples, and the excitation plots
show every branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lkdvos lkdvos changed the title Extend plot support for entanglementplot and transferplot to Makie.jl Makie.jl plotting extension, deprecate Plots.jl recipes Nov 4, 2026
@lkdvos

lkdvos commented Nov 4, 2026

Copy link
Copy Markdown
Member

@borisdevos I made an attempt at reviving this, but could use some of your opinions. One of the important issues I found with the previous approach is that both the Plots as well as the Makie implementations were writing into the defined MPSKit.entanglementplot, and as a result if you accidentally have both of these packages loaded, depending on the order in which they are included you would get a different backend. I don't think that is really something we can have, so I tried to bypass this here by making the Makie ones entanglement_plot and transfer_plot with underscores, while deprecating the Plots ones entanglementplot and transferplot, to remain backwards compatible.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@borisdevos

Copy link
Copy Markdown
Member Author

I can take a closer look at this tomorrow or Friday if you want, I'm mostly just curious about how the output actually looks like. Though the code looks a lot cleaner! In terms of the API I have no strong opinion, I had always just assumed users would never load multiple plot backends at the same time, but the *_plot is in line with the *_spectrum so that's good.

@lkdvos

lkdvos commented Nov 5, 2026

Copy link
Copy Markdown
Member

No rush about this, I think the output is shown in some of the examples mostly, so that might give an idea? It's not super urgent, i think we can also still swap stuff around afterwards if we're happy with the function names as well

@borisdevos borisdevos left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a fan of the plots! The only nitpick I have is that I think the entanglement spectra y-tick labels should be integer powers. Like in the spin-1 Heisenberg example, the psi_minus plot has 10^{0.0}, 10^{-2.5} and 10^{-5.0}. Makie just picks these based on the y-limit. But this is really nitpicky, feel free to ignore.

In general I think stylistic choices can be altered later. I can't approve, but the code is fine by me.

@lkdvos

lkdvos commented Nov 5, 2026

Copy link
Copy Markdown
Member

I guess that would still be configurable by setting yticks yourself, so I will merge as-is for now, mostly because I'm lazy 😉

@lkdvos
lkdvos merged commit 263fe27 into main Nov 5, 2026
29 checks passed
@lkdvos
lkdvos deleted the bd/plotting branch November 5, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants