-
-
Notifications
You must be signed in to change notification settings - Fork 359
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
[BUG] Recent update causes angled axis labels to be mis-positioned #3776
Comments
Probably caused by #3587. There is a trigger on alignment for |
45 and higher seems to be fine. Lower than 45 has the problem. |
I still have to think what we should do here. Goal is to keep #3581 fixed. We could hardcode a factor e.g. function gr_set_tickfont(sp, letter)
...
# invalidate alignment changes for small rotations (|θ| < θᵣ)
hardcoded_factor = 2
trigger(rot) = hardcoded_factor * abs(sind(rot)) < abs(cosd(rot)) ? 0 : sign(rot)
rot = axis[:rotation]
if letter === :x || (RecipesPipeline.is3d(sp) && letter === :y)
halign = (:left, :hcenter, :right)[trigger(rot) + 2]
valign = (axis[:mirror] ? :bottom : :top, :vcenter)[trigger(abs(rot)) + 1]
else
...
end
...
end , but I prefer to avoid piracy and propose something generic. @BioTurboNick, maybe you have a suggestion for this ? mwe using Measures, Random, Dates, Plots
Random.seed!(2018)
main() = begin
days = 31
position = cumsum(randn(days))
x = Date(2018, 1, 1):Day(1):Date(2018, 1, 31)
ticks = [x[i] for i in 1:5:length(x)]
for θ ∈ 0:10:120
plot(
x, position,
xlabel = "Date",
ylabel = "Position",
title = "Track of random walker",
xticks = ticks,
xrotation = θ
)
png("bug-$θ")
end
return
end
main() |
I'll give it some thought. |
Isn't that what's currently done ? I was thinking of maybe increasing offset based on rotation: Line 1564 in 8b6073c
|
Ha yeah, wrote this PR 2 months ago and already forgot what I coded 😆. Some possible fix: # invalidate alignment changes for small rotations around default position
trigger(rot) = abs(sind(rot)) < .25 ? 0 : sign(rot) |
There's probably a simpler way to write this but this is a little more general for all rotations I think: rot = axis[:rotation] % 360
if letter === :x || (RecipesPipeline.is3d(sp) && letter === :y)
if -90 < rot < 90 || rot < -270 || rot > 270
valign = axis[:mirror] ? :bottom : :top
elseif abs(rot) % 90 == 0 # -270, -90, 90, 270
valign = :vcenter
else
valign = axis[:mirror] ? :top : :bottom
end
if 0 < rot < 360
halign = axis[:mirror] ? :left : :right
elseif abs(rot) % 180 == 0 # -180, 0, 180
halign = :hcenter
else
halign = axis[:mirror] ? :right : :left
end
else
if 0 < rot < 360
valign = axis[:mirror] ? :top : :bottom
elseif abs(rot) % 180 == 0 # -180, 0, 180
valign = :vcenter
else
valign = axis[:mirror] ? :bottom : :top
end
if -90 < rot < 90 || rot < -270 || rot > 270
halign = axis[:mirror] ? :left : :right
elseif abs(rot) % 90 == 0 # -270, -90, 90, 270
halign = :hcenter
else
halign = axis[:mirror] ? :right : :left
end
end |
Suggest this modification to look at y axis and mirrored axes simultaneously. main() = begin
days = 31
position = cumsum(randn(days)) .* 10000
x = Date(2018, 1, 1):Day(1):Date(2018, 1, 31)
ticks = [x[i] for i in 1:5:length(x)]
for mir ∈ [true, false]
for θ ∈ -120:10:120
plot(
x, position,
xlabel = "Date",
ylabel = "Position",
title = "Track of random walker",
xticks = ticks,
xrotation = θ,
yrotation = θ,
xmirror = mir,
ymirror = mir
)
png("bug-$θ-$mir")
end
end
return
end |
Looks good, explicit is sometimes more readable. Can you make a PR out of it ? You'll need to regenerate reference images for GR I guess. Suggested changes writing valign = if -90 < rot < 90 || rot < -270 || rot > 270
axis[:mirror] ? :bottom : :top
elseif abs(rot) % 90 == 0 # -270, -90, 90, 270
:vcenter
else
axis[:mirror] ? :top : :bottom
end
[...] |
I'm not sure how the reference images work, where do I start with that? |
Ref: https://docs.juliaplots.org/latest/contributing/#VisualRegressionTests
|
Details
It looks like the tick labels are being rotated around their center, but not offset like they used to be.
Backends
This bug occurs on ( insert
x
below )Plots.tick_padding
withERROR: MethodError: no method matching length(::Date)
within a call tomaximum
Versions
Plots.jl version: 1.21.1
Backend version (
]st -m <backend(s)>
): 0.58.1Output of
versioninfo()
:The text was updated successfully, but these errors were encountered: