6

Bug persisting in 13.1.0 [CASE:4953032]


For antialiased export, I'm using the following pattern:

Rasterize[Style[plot, Antialiasing -> True], ImageSize -> 800,
  RasterSize -> 1600]

However, this introduces "polygon" artifacts in my RegionPlot plots, any tips for a way around it?

enter image description here

nf[x_] := NumberForm[x, {3, 3}];
rotateVec[angle_, vec_] := N[RotationMatrix[angle] . vec];
simpleNorm[{{a_, b_}, {c_, d_}}] := 
  Max[Sqrt[
   a^2 + b^2 + c^2 + d^2 - 
    Sqrt[-4 (b c - a d)^2 + (a^2 + b^2 + c^2 + d^2)^2]]/Sqrt[2], Sqrt[
   a^2 + b^2 + c^2 + d^2 + 
    Sqrt[-4 (b c - a d)^2 + (a^2 + b^2 + c^2 + d^2)^2]]/Sqrt[2]];
xvec1 = {1, 0};
getBatch[theta_] := {1/2 xvec1, rotateVec[theta, xvec1]};

standardColors = ColorData[97, "ColorList"];

d = 2; ii = IdentityMatrix[d]; bound = 2.;

setTheta[t0_] := ( theta = t0; H = With[{X = getBatch[theta]}, X . X[Transpose]]; Ta[alpha_] := ii - 2 alpha H + alpha^2 H . H; obj[alpha_] := simpleNorm@Ta@alpha; sol = NMinimize[obj[alpha], alpha]; point = {alpha /. Last[sol], First@sol}; curvePlot = Plot[Norm@Ta@alpha, {alpha, alphaStart, alphaEnd}, Epilog -> {PointSize[Large], Red, Point[point]}, AxesOrigin -> {0, 0}]; tracePlot = Plot[Tr@Ta@alpha, {alpha, alphaStart, alphaEnd}, PlotStyle -> {Directive[Dashed, standardColors[[2]]]}]; arrowsPlot = Graphics[Arrow[{{0, 0}, #}] & /@ getBatch[theta]]; );

genPlot[alpha_] := Module[{}, alphaStart = 0; alphaEnd = 3.;

mat0 = Ta[alpha]; R = Norm[mat0]; curvePositionPlot = ListPlot[{{alpha, Norm@mat0}}, Filling -> Axis, PlotStyle -> PointSize[Large], FillingStyle -> Dashed]; curvePositionPlot2 = ListPlot[{{alpha, Tr@mat0}}, PlotStyle -> PointSize[Large], FillingStyle -> Dashed]; boundsPlot0 = ContourPlot[{{x1, x2} . ii . {x1, x2} == R, {x1, x2} . ii . {x1, x2} == Tr@mat0}, {x1, -bound, bound}, {x2, -bound, bound}, Frame -> False, ContourStyle -> {standardColors[[1]], Directive[standardColors[[2]], Dashed]}]; boundsPlot1 = RegionPlot[{x1, x2} . PseudoInverse[mat0] . {x1, x2} <= 1, {x1, -bound, bound}, {x2, -bound, bound}, PlotStyle -> standardColors[[3]]];

boundsPlot = Show[boundsPlot0, boundsPlot1, arrowsPlot]; curvePlot0 = Show[curvePlot, curvePositionPlot, tracePlot, curvePositionPlot2, PlotLabel -> StringForm["trace=norm=", nf@Tr@mat0, nf@R]]; GraphicsRow[{boundsPlot, curvePlot0}, 0, Spacings -> 0] ]; linePlot = ContourPlot[{x1, x2} . CholeskyDecomposition[H] == 0, {x1, -bound, bound}, {x2, -bound, bound}, ContourStyle -> Directive[Orange, Dashed], PlotLabel -> StringForm["step=``", k]]; setTheta[Pi/4]; Rasterize[Style[genPlot[0.5], Antialiasing -> True], ImageSize -> 800, RasterSize -> 1600]

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
Yaroslav Bulatov
  • 7,793
  • 1
  • 19
  • 44
  • 4
    I had filed this on Jul 13. A day later they confirmed this as a bug, case number 4953032. "The cause here is slightly overlapping multi-polygons with transparency in them. The effective opaque fill color of the default PlotStyle when overlaid on a white background. Our developers are investigating the issue, and we will notify you when the issue is fixed". – Andreas Lauschke Sep 08 '22 at 21:14
  • @MarcoB just tried the solutions in that post and it didn't work -- the lines reappear when calling Rasterize with antialiasing – Yaroslav Bulatov Sep 08 '22 at 21:20
  • Maybe something like this could work? https://mathematica.stackexchange.com/a/257042/4346 – Greg Hurst Sep 09 '22 at 00:21

1 Answers1

5

Apply Antialiasing -> False to Polygons:

Rasterize[Style[genPlot[0.5] /. p_Polygon :> Style[p, Antialiasing -> False], 
  Antialiasing -> True], ImageSize -> 800, RasterSize -> 1600]

output

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
  • upon closer examination of image quality side-by-side, it seems like default Export["anim.gif",frames] already does something like this, lines seem antialiased, and no polygon artifacts – Yaroslav Bulatov Sep 09 '22 at 03:22