Let us employ the Region
-based functionality for constructing a vector figure with transparent (empty) plot markers without plotted lines going through them. The advantage of this approach is that the plot markers are really transparent, as opposed to my previous answer, where the transparency was a simulation. The plotted lines do not go through the markers, because the corresponding portions of them are explicitly removed using RegionDifference
. The parameter aspectRatio
here defines the aspect ratio of the full plot range area (not of the whole figure), as it does the option AspectRatio
. The amount of padding may be controlled using the parameners of the padPlotRange
function (or, alternatively, the full plot range paddedPlotRangefullPlotRange
can be set explicitly). The perfect result is achieved when the options AspectRatio -> aspectRatio
and PlotRange -> paddedPlotRangefullPlotRange, PlotRangePadding -> None
are set for the final Graphics
.
Clear[padPlotRange, createLineWithMarkers, createLegend];
(* Uniformly expands the plotting area, taking into account the aspect ratio *)
padPlotRange[padding_ : .05, aspectRatio_ : 1/GoldenRatio][plotRange_] :=
Transpose[ScalingTransform[
1 + 2 {padding, padding/aspectRatio}, Mean /@ plotRange][plotRange\[Transpose]]]
(* Generates graphics primitives representing the lines and the markers *)
createLineWithMarkers[{shape_, spec_ : .02}, pts_, fullPlotRange_,
aspectRatio_ : 1/GoldenRatio] :=
Module[{rt, rtBack, markerPrimsResc, linePrimsResc, ptsResc},
rt = RescalingTransform[fullPlotRange, {{0, 1}, {0, aspectRatio}}];
rtBack = InverseFunction[rt];
ptsResc = rt[pts];
markerPrimsResc = PolygonMarker[shapeResourceFunction["PolygonMarker"][shape, spec, ptsResc];
linePrimsResc =
MeshPrimitives[RegionDifference[Line[ptsResc], RegionUnion @@ markerPrimsResc],
1] /. _MeshPrimitives :> {};
Join[linePrimsResc, markerPrimsResc] /. (h : Line | Polygon)[ptsResc_] :>
h@rtBack[ptsResc]];
(* Generates graphics primitives representing a legend *)
createLegend[markerSpecs_, labels_, {verticalStep_, labelStep_, lineLength_ : .06},
legendPosition_, styles_, fullPlotRange_, aspectRatio_ : 1/GoldenRatio] :=
Module[{rt, shifts, protect},
rt = RescalingTransform[{{0, 1}, {0, aspectRatio}}, fullPlotRange];
Table[Join[styles[[i]],
MeshPrimitives[
RegionDifference[Line[{{-lineLength/2, 0}, {lineLength/2, 0}}],
PolygonMarkerResourceFunction["PolygonMarker"] @@ markerSpecs[[i]]], 1] /. _MeshPrimitives :> {},
{PolygonMarkerResourceFunction["PolygonMarker"] @@ markerSpecs[[i]], Text[protect@labels[[i]], {labelStep, 0}]}] /.
{protect[l_] :> l, {x_?NumericQ, y_?NumericQ} :>
(rt[{x, y} + {0, (Length[markers] - i) verticalStep} + legendPosition])},
{i, Length[markers]}]];