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

Axis as marker= #4862

Open
jariji opened this issue Mar 11, 2025 · 4 comments
Open

Axis as marker= #4862

jariji opened this issue Mar 11, 2025 · 4 comments
Labels
enhancement Feature requests and enhancements

Comments

@jariji
Copy link
Contributor

jariji commented Mar 11, 2025

Feature description

I keep seeing cool plots which have axes positioned at data coordinates. I would like to try using an Axis (or some wrapper around it) as a scatter marker.

I realize it's possible to do this manually using pixel coordinates. My question is if there's any possibility of using the marker= API to simplify such usage.

Plots from paper:

Image

Image

Image

@jariji jariji added the enhancement Feature requests and enhancements label Mar 11, 2025
@asinghvi17
Copy link
Member

I guess we could have a marker conversion that calls colorbuffer on a Scene? It's not exactly live rendering, though...

@aplavin
Copy link
Contributor

aplavin commented Mar 11, 2025

colorbuffer is exactly what I thought as well:

Image

scatter(randn(10), randn(10), marker=map(1:10) do _
	fig, ax, _ = scatter(cumsum(randn(100)), figure=(;size=(150,150)))
	hidedecorations!(ax)
	Matrix(colorbuffer(fig))
end, markersize=100)

@asinghvi17
Copy link
Member

This could also be done with MakieTeX's SVGDocument or PDFDocument if you want true vector rendering

@SimonDanisch
Copy link
Member

We could also think about something like this:

import Makie.SpecApi as S
@recipe PlotScatter (positions,) begin
    marker = nothing
    markersize = (60, 60)
end

Makie.conversion_trait(::Type{<:PlotScatter}) = Makie.PointBased()

Makie.data_limits(p::PlotScatter) = Rect3f(p.positions[])
function Makie.plot!(p::PlotScatter)
    pscene = Makie.parent_scene(p)
    broadcast_foreach(p.positions[], p.marker[], p.markersize[]) do pos, marker, markersize
        rectpix = Observable(Rect2f(0, 0, 0, 0))
        rectpix_off = Observable(Rect2i(0, 0, 0, 0))
        onany(pscene.camera.projectionview, pscene.viewport; update=true) do pv, vp
            ppix = Makie.project(pscene, pos)
            rectpix[] = Rect2i(ppix, markersize)
            rectpix_off[] = Rect2i(vp.origin .+ ppix, markersize)
        end
            
        sub = Scene(pscene, rectpix_off)
        cam2d!(sub)
        pl = plotlist!(sub, marker)
        center!(sub)
        linesegments!(p, rectpix, space=:pixel)
    end

    return
end


f, ax, pl = plotscatter(rand(Point2f, 10); marker=map(1:10) do x
    S.Lines(cumsum(randn(100)), color=rand(RGBf))
end)
limits!(ax, Rect2f(data_limits(ax.scene))) # honestly not sure why this is needed
f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature requests and enhancements
Projects
None yet
Development

No branches or pull requests

4 participants