Better twinx (#3564)
* improve twinx * add tests, disable gridlines of twinx
This commit is contained in:
parent
849d31d57f
commit
990e0f3f7f
@ -775,9 +775,17 @@ end
|
|||||||
|
|
||||||
"Adds a new, empty subplot overlayed on top of `sp`, with a mirrored y-axis and linked x-axis."
|
"Adds a new, empty subplot overlayed on top of `sp`, with a mirrored y-axis and linked x-axis."
|
||||||
function twinx(sp::Subplot)
|
function twinx(sp::Subplot)
|
||||||
sp[:right_margin] = max(sp[:right_margin], 30px)
|
plot!(sp.plt,
|
||||||
plot!(sp.plt, inset = (sp[:subplot_index], bbox(0,0,1,1)))
|
inset = (sp[:subplot_index], bbox(0,0,1,1)),
|
||||||
|
right_margin = sp[:right_margin],
|
||||||
|
left_margin = sp[:left_margin],
|
||||||
|
top_margin = sp[:top_margin],
|
||||||
|
bottom_margin = sp[:bottom_margin],
|
||||||
|
)
|
||||||
twinsp = sp.plt.subplots[end]
|
twinsp = sp.plt.subplots[end]
|
||||||
|
twinsp[:xaxis][:grid] = false
|
||||||
|
twinsp[:yaxis][:grid] = false
|
||||||
|
twinsp[:xaxis][:showaxis] = false
|
||||||
twinsp[:yaxis][:mirror] = true
|
twinsp[:yaxis][:mirror] = true
|
||||||
twinsp[:background_color_inside] = RGBA{Float64}(0,0,0,0)
|
twinsp[:background_color_inside] = RGBA{Float64}(0,0,0,0)
|
||||||
link_axes!(sp[:xaxis], twinsp[:xaxis])
|
link_axes!(sp[:xaxis], twinsp[:xaxis])
|
||||||
|
|||||||
@ -35,13 +35,13 @@ end
|
|||||||
@testset "Axis limits" begin
|
@testset "Axis limits" begin
|
||||||
pl = plot(1:5, xlims=:symmetric, widen = false)
|
pl = plot(1:5, xlims=:symmetric, widen = false)
|
||||||
@test Plots.xlims(pl) == (-5, 5)
|
@test Plots.xlims(pl) == (-5, 5)
|
||||||
|
|
||||||
pl = plot(1:3)
|
pl = plot(1:3)
|
||||||
@test Plots.xlims(pl) == Plots.widen(1,3)
|
@test Plots.xlims(pl) == Plots.widen(1,3)
|
||||||
|
|
||||||
pl = plot([1.05,2.0,2.95], ylims=:round)
|
pl = plot([1.05,2.0,2.95], ylims=:round)
|
||||||
@test Plots.ylims(pl) == (1, 3)
|
@test Plots.ylims(pl) == (1, 3)
|
||||||
|
|
||||||
pl = plot(1:3, xlims=(1,5))
|
pl = plot(1:3, xlims=(1,5))
|
||||||
@test Plots.xlims(pl) == (1, 5)
|
@test Plots.xlims(pl) == (1, 5)
|
||||||
|
|
||||||
@ -53,3 +53,13 @@ end
|
|||||||
ql = quiver([1, 2], [2, 1], [3, 4], quiver = ([1, -1], [0, 0], [1, -0.5]), arrow=true)
|
ql = quiver([1, 2], [2, 1], [3, 4], quiver = ([1, -1], [0, 0], [1, -0.5]), arrow=true)
|
||||||
@test ql[1][:projection] == "3d"
|
@test ql[1][:projection] == "3d"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@testset "twinx" begin
|
||||||
|
pl = plot(1:10, margin = 2Plots.cm)
|
||||||
|
twpl = twinx(pl)
|
||||||
|
pl! = plot!(twinx(), -(1:10))
|
||||||
|
@test twpl[:right_margin] == 2Plots.cm
|
||||||
|
@test twpl[:left_margin] == 2Plots.cm
|
||||||
|
@test twpl[:top_margin] == 2Plots.cm
|
||||||
|
@test twpl[:bottom_margin] == 2Plots.cm
|
||||||
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user