Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update plot kwarg #382

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions docs/src/math/knotvector.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ A knot vector can be visualized with `Plots.plot`.
k1 = KnotVector([0.0, 1.5, 2.5, 5.5, 8.0, 9.0, 9.5, 10.0])
plot(k1; label="k1")
k2 = knotvector"1231123"
plot!(k2; label="k2", shift_y=0.5, ylims=(-0.1,1), xticks=0:10)
plot!(k2; label="k2", offset=0.5, ylims=(-0.1,1), xticks=0:10)
savefig("knotvector.png") # hide
nothing # hide
```
Expand All @@ -60,13 +60,13 @@ nothing # hide
```@example math_knotvector
k1 = knotvector"1 2 1 11 2 31"
k2 = knotvector"113 1 12 2 32 1 1"
plot(k1; shift_y=-0.0, label="k1", xticks=1:18, yticks=nothing, legend=:right)
plot!(k2; shift_y=-0.2, label="k2")
plot!(k1+k2; shift_y=-0.4, label="k1+k2")
plot!(2k1; shift_y=-0.6, label="2k1")
plot!(unique(k1); shift_y=-0.8, label="unique(k1)")
plot!(unique(k2); shift_y=-1.0, label="unique(k2)")
plot!(unique(k1+k2); shift_y=-1.2, label="unique(k1+k2)")
plot(k1; offset=-0.0, label="k1", xticks=1:18, yticks=nothing, legend=:right)
plot!(k2; offset=-0.2, label="k2")
plot!(k1+k2; offset=-0.4, label="k1+k2")
plot!(2k1; offset=-0.6, label="2k1")
plot!(unique(k1); offset=-0.8, label="unique(k1)")
plot!(unique(k2); offset=-1.0, label="unique(k2)")
plot!(unique(k1+k2); offset=-1.2, label="unique(k1+k2)")
savefig("knotvector_operations.png") # hide
nothing # hide
```
Expand Down
8 changes: 4 additions & 4 deletions ext/BasicBSplineRecipesBaseExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
using StaticArrays

# B-spline space
@recipe function f(k::AbstractKnotVector; gap_y=0.02, shift_y=0.0, plane=:xy)
@recipe function f(k::AbstractKnotVector; gap=0.02, offset=0.0, plane=:xy)

Check warning on line 9 in ext/BasicBSplineRecipesBaseExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/BasicBSplineRecipesBaseExt.jl#L9

Added line #L9 was not covered by tests
u = BasicBSpline._vec(k)
l = length(u)
v = fill(float(shift_y), l)
v = fill(float(offset), l)
for i in 2:l
if u[i-1] == u[i]
v[i] = v[i-1] - gap_y
v[i] = v[i-1] - gap
end
end
seriestype := :scatter
delete!(plotattributes, :gap_y)
delete!(plotattributes, :gap)
delete!(plotattributes, :plane)
if plane === :xy
u, v
Expand Down
4 changes: 2 additions & 2 deletions test/test_Plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@

pl = plot(P1, label="P1", color=:red)
plot!(P2, label="P2", color=:green)
plot!(knotvector(P1), label="k1", gap_y=0.01, color=:red)
plot!(knotvector(P2); label="k2", gap_y=0.01, shift_y=-0.03, color=:green)
plot!(knotvector(P1), label="k1", gap=0.01, color=:red)
plot!(knotvector(P2); label="k2", gap=0.01, offset=-0.03, color=:green)

path_img = joinpath(dir_out, "bspline_spaces_and_their_knotvectors.png")
@test !isfile(path_img)
Expand Down
Loading