From 331a25a0b91a27cea84fe5019bd5e230011fc27e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefanos=20Carlstr=C3=B6m?= Date: Mon, 3 Apr 2023 14:11:21 +0200 Subject: [PATCH] Transitioned documentation plots to Python{Call,Plot} --- .github/workflows/CI.yml | 11 ++------- .gitignore | 2 ++ docs/CondaPkg.toml | 2 ++ docs/Project.toml | 19 +++++++++++++--- docs/plots.jl | 48 ++++++++++++++++++---------------------- 5 files changed, 44 insertions(+), 38 deletions(-) create mode 100644 docs/CondaPkg.toml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 140fff9..ff21261 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -59,16 +59,9 @@ jobs: - run: | julia --project=docs -e ' using Pkg - pkg"add https://github.com/jagot/Jagot.jl"' - - run: | - julia --project=docs -e ' - using Pkg - Pkg.develop(PackageSpec(path=pwd())) Pkg.instantiate() - pkg"build PyPlot"' - env: - PYTHON: "" - - run: julia --project=docs docs/make.jl + pkg"add https://github.com/jagot/Jagot.jl"' + - uses: julia-actions/julia-docdeploy@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} diff --git a/.gitignore b/.gitignore index 0545f2b..72481cc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ *.jl.mem *~ /docs/src/figures/ +Manifest.toml +.CondaPkg \ No newline at end of file diff --git a/docs/CondaPkg.toml b/docs/CondaPkg.toml new file mode 100644 index 0000000..7d59288 --- /dev/null +++ b/docs/CondaPkg.toml @@ -0,0 +1,2 @@ +[deps] +matplotlib = ">=3" diff --git a/docs/Project.toml b/docs/Project.toml index 94e550c..bd30b44 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -2,17 +2,30 @@ AngularMomentumAlgebra = "0bb1b1ac-0216-11e9-361b-bb110c659ce1" AtomicLevels = "10933b4c-d60f-11e8-1fc6-bd9035a249a1" CompactBases = "2c0377a8-7469-4ebd-be0f-82e501f20078" +CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab" ContinuumArrays = "7ae1f121-cc2c-504b-ac30-9b923412ae5c" CoulombIntegrals = "42e5845a-f9f1-11e8-0afe-795ea56ed153" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" EnergyExpressions = "f4b57a2e-27c7-11e9-0cb0-edd185b706f6" IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953" -Jagot = "84fb645a-ffa8-56cf-983b-ade63a92b20c" LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02" -PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0" -PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee" +PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d" +PythonPlot = "274fc56d-3b97-40fa-a1cd-1b4a50311bf9" QuasiArrays = "c4ea9172-b204-11e9-377d-29865faadc5c" SolverTraces = "619b3e1a-df4a-11e8-3b0b-a997e0925a8d" [compat] +AngularMomentumAlgebra = "0.1, 0.2, 0.3" +AtomicLevels = "0.1.3" +CompactBases = "0.3" +CondaPkg = "0.2" +ContinuumArrays = "0.10, 0.11, 0.12" +CoulombIntegrals = "0.1.1" Documenter = "0.27" +EnergyExpressions = "0.1" +IntervalSets = "0.7" +LazyArrays = "0.22, 1" +PythonCall = "0.9" +PythonPlot = "1" +QuasiArrays = "0.9" +SolverTraces = "0.1" diff --git a/docs/plots.jl b/docs/plots.jl index 6069c21..33059ef 100644 --- a/docs/plots.jl +++ b/docs/plots.jl @@ -1,11 +1,11 @@ -using PyPlot +using PythonPlot using Jagot.plotting plot_style("ggplot") -using PyCall +using PythonCall Cycler = pyimport("cycler") -plt.rc("axes", prop_cycle=(plt.rcParams["axes.prop_cycle"] + - Cycler.cycler("linestyle", ["-","--",":","-.",":","-","--"]))) +pyplot.rc("axes", prop_cycle=(pyplot.rcParams["axes.prop_cycle"] + + Cycler.cycler("linestyle", ["-","--",":","-.",":","-","--"]))) using Statistics using Random @@ -23,29 +23,24 @@ function mean_color(color::String) mean([c.r,c.g,c.b]) end +mean_color(color::Py) = mean_color(pyconvert(String, color)) + lerp(a,b,t) = (1-t)*a + t*b mean_position(x, ϕ) = ϕ'*Diagonal(x)*ϕ/(ϕ'ϕ) -function cfigure(fun::Function, figname; clear=true, tight=true, kwargs...) - figure(figname; kwargs...) - clear && clf() - fun() - tight && tight_layout() -end - -function csubplot(fun::Function, args...; nox=false, noy=false) - ax = subplot(args...) - fun() - if nox - no_tick_labels(:x) - xlabel("") - end - if noy - no_tick_labels(:y) - ylabel("") +function savedocfig(name,dir="figures") + fig = gcf() + filename = joinpath(@__DIR__, "src", dir, "$(name).svg") + savefig(filename, + transparent=true, + facecolor=fig.get_facecolor()) + PythonPlot.close("all") + if isfile(filename) + println("Saved $(name) to $(filename)") + else + @warn "Saving $(name) to $(filename) failed" end - ax end function plot_orbitals(atom::Atom; nrplot=1000, plot_basis=false, @@ -120,7 +115,7 @@ function hydrogen() gst = ground_state(nucleus) atom = Atom(R, [spin_configurations(gst)[1]], nucleus) plot_orbitals(atom) - savefig("docs/src/figures/hydrogen.svg") + savedocfig("hydrogen") end function helium() @@ -142,7 +137,7 @@ function helium() end legend(framealpha=0.75,ncol=2) end - savefig("docs/src/figures/helium.svg") + savedocfig("helium") end function beryllium(grid_type) @@ -153,7 +148,7 @@ function beryllium(grid_type) fock = Fock(atom) optimize!(fock,ω=0.999,ωmax=1-1e-3,scf_method=:arnoldi) plot_orbitals(atom) - savefig("docs/src/figures/beryllium-$(grid_type).svg") + savedocfig("beryllium-$(grid_type)") end macro echo(expr) @@ -162,7 +157,8 @@ macro echo(expr) end @info "Documentation plots" -mkpath("docs/src/figures") +fig_dir = joinpath(@__DIR__, "src", "figures") +mkpath(fig_dir) @echo hydrogen() @echo helium() @echo beryllium(:fedvr)