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

Cannot use :linestyle in poly!(…, cycle=[…]) #4544

Open
3 tasks done
dpaetzel opened this issue Oct 29, 2024 · 4 comments
Open
3 tasks done

Cannot use :linestyle in poly!(…, cycle=[…]) #4544

dpaetzel opened this issue Oct 29, 2024 · 4 comments
Labels
bug Cycle (Color) cycling

Comments

@dpaetzel
Copy link

dpaetzel commented Oct 29, 2024

Hi, thank you for developing and maintaining this library! 🙂

I'm trying to get poly! to cycle not over colors but over line styles (mainly to have a fall back for people with color vision deficiencies). However, that does not work (or I may be doing something wrong here).

For simplicity, I copied and adjusted the poly! example from the docs.

using CairoMakie
using Makie.GeometryBasics


f = Figure()
Axis(f[1, 1])
poly!(
    [Rect(i, j, 0.75, 0.5) for i = 1:3 for j = 1:3],
    color = :white,
    strokewidth = 2,
    cycle = [:linestyle],
    linestyle = [
        :solid,
        :dash,
        :dot,
        :dashdot,
        (:dash, :loose),
        (:dot, :loose),
        (:dashdot, :loose),
        (:dash, :dense),
        (:dot, :dense),
        (:dashdot, :dense),
    ],
),
f

This throws the following error:

┌ Warning: Using a `Vector{<:Real}` as a linestyle attribute is deprecated. Wrap it in a `Linestyle`.
└ @ Makie ~/.julia/packages/Makie/6c4lt/src/conversions.jl:1079
Error showing value of type Figure:
ERROR: MethodError: Cannot `convert` an object of type Symbol to an object of type Float32

Closest candidates are:
  convert(::Type{T}, ::IntervalArithmetic.ExactReal) where T<:Real
   @ IntervalArithmetic ~/.julia/packages/IntervalArithmetic/KkeZ0/src/intervals/exact_literals.jl:111
  convert(::Type{T}, ::Unitful.Quantity) where T<:Real
   @ Unitful ~/.julia/packages/Unitful/GYzMo/src/conversion.jl:139
  convert(::Type{T}, ::Unitful.Level) where T<:Real
   @ Unitful ~/.julia/packages/Unitful/GYzMo/src/logarithm.jl:22
  ...

Stacktrace:
(long stacktrace redacted to not clutter too much)

I also tried to force the Linestyle type by applying Makie.to_linestyle. as well as (Linestyle ∘ Makie.to_linestyle). but to no avail.

  • what version of Makie are you running? (]st -m Makie)

    [ee78f7c6] Makie v0.21.14
    
  • can you reproduce the bug with a fresh environment ? (]activate --temp; add Makie)

    Yes.

  • What platform + GPU are you on?

    NixOS, not using GPU. But quite sure it has nothing to do with the platform I'm using.

@dpaetzel dpaetzel added the bug label Oct 29, 2024
@SimonDanisch
Copy link
Member

Cycling is only supported to cycle through a palette on a per plot basis, not with one big plot.

using CairoMakie
using Makie.GeometryBasics


# Pass the figure a theme with a new palette
f = Figure(palette=(; linestyle=[
    :solid,
    :dash,
    :dot,
    :dashdot,
    (:dash, :loose),
    (:dot, :loose),
    (:dashdot, :loose),
    (:dash, :dense),
    (:dot, :dense),
    (:dashdot, :dense),
]))
Axis(f[1, 1])
for i in 1:3, j in 1:3
    poly!(
        Rect(i, j, 0.75, 0.5),
        color = :white,
        strokewidth = 2,
        cycle = [:linestyle],
    )
end
f

This works, but will be a bit slower then using one poly call.

@dpaetzel
Copy link
Author

(Something went wrong when posting my reply. I hope this won't be duplicated now; if so, I'm sorry!)

Thanks for the reply! Is it intentional that strokecolor and linestyle behave so differently? After all, I can simply do strokecolor=1:9 and it just works?

f = Figure()
Axis(f[1, 1])
poly!(
    [Rect(i, j, 0.75, 0.5) for i = 1:3 for j = 1:3],
    color = :white,
    strokewidth = 2,
    strokecolor = 1:9,
)
display(f)

@dpaetzel
Copy link
Author

To add to this further: In the end, I want to combine changing strokecolor with changing linestyle. However, building on your example, the following does not seem to work?

f = Figure(;
    palette = (;
        linestyle = [
            :solid,
            :dash,
            :dot,
            :dashdot,
            (:dash, :loose),
            (:dot, :loose),
            (:dashdot, :loose),
            (:dash, :dense),
            (:dot, :dense),
            (:dashdot, :dense),
        ],
        strokecolor = Makie.wong_colors(),
    ),
)
Axis(f[1, 1])
for rect in [Rect(i, j, 0.75, 0.5) for i = 1:3 for j = 1:3]
    poly!(rect, color = :white, strokewidth = 2, cycle = [:linestyle, :strokecolor])
end
display(f)

It doesn't throw an error but it does not change the strokecolor either:

Image

@jkrumbiegel
Copy link
Member

The color doesn't change because by default the cycler goes through all values of cycle component 1 first, then all of 2, etc. You have nine rects and nine linestyles so you never see strokecolor 2. You can use Cycle(..., covary = true) if you want both to change at the same time:

f = Figure(;
    palette = (;
        linestyle = [
            :solid,
            :dash,
            :dot,
            :dashdot,
            (:dash, :loose),
            (:dot, :loose),
            (:dashdot, :loose),
            (:dash, :dense),
            (:dot, :dense),
            (:dashdot, :dense),
        ],
        strokecolor = Makie.wong_colors(),
    ),
)
Axis(f[1, 1])
for rect in [Rect(i, j, 0.75, 0.5) for i = 1:3 for j = 1:3]
    poly!(rect, color = :white, strokewidth = 2, cycle = Cycle([:linestyle, :strokecolor], covary = true))
end
display(f)

Image

@ffreyer ffreyer added the Cycle (Color) cycling label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Cycle (Color) cycling
Projects
None yet
Development

No branches or pull requests

4 participants