e3c6
1
In Makie, how do you increase the markersize of the legend, even though the markersize used in the plot is small?
I have a scatter plot with many points so I set a small marker size. But the same markersize in the legend is too small to see.
I am using axislegend
to construct the legend, so ideally a setting with that function would be neat.
4 Likes
e3c6
2
Sorry to revive this, but I never got a reply. Would be nice to have a way to control the marker size in the legend.
jules
3
I only have this hack using internals currently
f, ax, _ = scatter(randn(10000, 2), markersize = 1, color = :red, label = "Reds")
scatter!(randn(10000, 2) .+ 5, markersize = 1, color = :blue, label = "Blues")
leg = Legend(f[1, 2], ax)
for i in 1:2
leg.entrygroups[][1][2][i].elements[1].attributes[:markersize] = Observable(20)
end
notify(leg.entrygroups)
f
You could do this without a hack by creating “dummy” plots:
f, ax, _ = scatter(randn(10000, 2), markersize = 1, color = :red)
scatter!(randn(10000, 2) .+ 5, markersize = 1, color = :blue,)
scatter_red = scatter!([], markersize = 20, color = :red, label = "Reds")
scatter_blue = scatter!([], markersize = 20, color = :blue, label = "Blues")
leg = Legend(f[1, 2], [scatter_red, scatter_blue])
f
1 Like
Hello,
To increase the marker size of the legend in Makie while keeping the plot markers small, adjust the markersize
property of the legend markers after creating the legend. There’s no direct setting in axislegend
, but you can achieve it like this
legend_marker_size = 10 # Adjust as needed
legend_scatter = scatter([NaN], [NaN], markersize = legend_marker_size, color = :black, label = “Legend”)
axislegend(scatterplot, legend_scatter)
for marker in legend_scatter
marker.markersize = legend_marker_size
I hope this will help you,
Thank you