Skip to content

Graphics2D: NumberForm, Rotate inside Text, PlotLabel issues #440

@kkoudas01

Description

@kkoudas01

The following code runs just fine on Wolfram Cloud.

Clear["Global`*"]

RiemannBar[box : {{x0_, x1_}, {y0_, y1_}}, {x_, y_}, _] := 
 Block[{area = (y1 + y0) (x1 - x0)},  Sow[area];
  {ChartElementData["Rectangle"][box, {}, {}], {Opacity[1], Black, Point[{x, y}]}, 
  If[Abs[area] < 10^-2, {}, {Opacity[1], Black,Text[Rotate[NumberForm[area, {Infinity, 2}], Pi/2], Mean /@ box]}]}]
  
RiemannPlot[f_, {x_, x0_, x1_, dx_: 1.}, opts___] := 
 Block[{plot, areas, extent, points, curve},
  extent = OptionValue[Flatten[{opts}], ExtentSize];
  points = 
   If[IntegerQ[dx], RandomReal[{x0, x1}, dx], 
    Switch[extent, Full, Range[x0, x1, dx], Left, 
     Range[x0 + dx, x1, dx], Right, Range[x0, x1 - dx, dx]]]; {plot, 
    areas} = 
   Reap[DiscretePlot[f, Evaluate@{x, points}, opts, ImageSize -> 275, 
     ExtentElementFunction -> RiemannBar, 
     FillingStyle -> Opacity[0.5], PlotStyle -> PointSize[Medium]]];
  Show[plot, Plot[f, {x, x0, x1}], 
   PlotLabel -> 
    Row[{"Estimated Area: ", Total[Flatten@areas], Spacer[10], 
      "Actual Area: ", NIntegrate[f, {x, x0, x1}]}], Frame -> True,   PlotRange -> All, Axes -> {True, False}]  ]
      
  RiemannPlot[BesselJ[5, x], {x, 0, 10, 0.5}, ExtentSize -> Full]

Specifically, it produces this image.

Image

However, when I run it on wljs, it produces this image.

Image

What’s going wrong? I’m not sure which command is causing the problem, so I’ll mention this one as the likely reason.

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions