Skip to main content
edited body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

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 paramenersparameters of the padPlotRange function (or, alternatively, the full plot range fullPlotRange can be set explicitly). The perfect result is achieved when the options AspectRatio -> aspectRatio and PlotRange -> fullPlotRange, PlotRangePadding -> None are set for the final Graphics.

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 fullPlotRange can be set explicitly). The perfect result is achieved when the options AspectRatio -> aspectRatio and PlotRange -> fullPlotRange, PlotRangePadding -> None are set for the final Graphics.

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 parameters of the padPlotRange function (or, alternatively, the full plot range fullPlotRange can be set explicitly). The perfect result is achieved when the options AspectRatio -> aspectRatio and PlotRange -> fullPlotRange, PlotRangePadding -> None are set for the final Graphics.

added 56 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

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]}]];

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 paddedPlotRange can be set explicitly). The perfect result is achieved when the options AspectRatio -> aspectRatio and PlotRange -> paddedPlotRange, 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[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}}], 
         PolygonMarker @@ markerSpecs[[i]]], 1] /. _MeshPrimitives :> {},
      {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]}]];

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 fullPlotRange can be set explicitly). The perfect result is achieved when the options AspectRatio -> aspectRatio and PlotRange -> fullPlotRange, 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 = ResourceFunction["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}}], 
         ResourceFunction["PolygonMarker"] @@ markerSpecs[[i]]], 1] /. _MeshPrimitives :> {},
      {ResourceFunction["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]}]];
added 151 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

Here we useLet 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 paddedPlotRange can be set explicitly). The perfect result is achieved when the options AspectRatio -> aspectRatio and PlotRange -> paddedPlotRange, PlotRangePadding -> None are set for the final Graphics.

Looks perfect.


Strongly related:

Here we use 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 paddedPlotRange can be set explicitly). The perfect result is achieved when the options AspectRatio -> aspectRatio and PlotRange -> paddedPlotRange, PlotRangePadding -> None are set for the final Graphics.

Looks perfect.

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 paddedPlotRange can be set explicitly). The perfect result is achieved when the options AspectRatio -> aspectRatio and PlotRange -> paddedPlotRange, PlotRangePadding -> None are set for the final Graphics.

Looks perfect.


Strongly related:

better implementation
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375
Loading
better implementation
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375
Loading
deleted 1 character in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375
Loading
added 3 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375
Loading
deleted 11 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375
Loading
added 40 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375
Loading
added 40 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375
Loading
added 93 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375
Loading
deleted 15 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375
Loading
added 882 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375
Loading
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375
Loading