4
$\begingroup$

I'm trying to generate a 3d-plot with mathematica that arranges numbers from a dataset of any size in a full circle as 3d-bars. In this process, the values ​​of the numbers reflect the height of the bars. The following example demonstrates it very well:

data={1,2,3,4};

out=

circular 3d-bar-chart

Can this be done with mathematica? If yes, how? Maybe someone here has a quick Solution for that :) Thanks in advance. Regards

$\endgroup$

1 Answer 1

8
$\begingroup$

Updated

Use Cuboid to draw any 3D BarChart.

Clear[values, n, cuboid, regs, r, pts, circle3];
values = {2.5, E, π, 4.15, 5.555, 6.45};
values = Reverse@values;
n = Length@values;
cuboid[h_] = Cuboid[{-1/2, -1/2, 0}, {1/2, 1/2, h}];
regs = Table[
   Show[HighlightMesh[
      cuboid@h, {Style[1, {Black, AbsoluteThickness[1]}], 
       Style[2, None]}], 
     RegionPlot3D[cuboid@h, Mesh -> {Range[Floor[h]]}, 
      MeshFunctions -> {#3 &}, AspectRatio -> Automatic, 
      Boxed -> False, MeshStyle -> {Black, AbsoluteThickness[1]}, 
      BoundaryStyle -> Thick, PlotStyle -> Pink]] // First, {h, 
    values}];
r = n;
pts = PadRight[#, 3] & /@ CirclePoints[{r, Pi}, n];
circle3[r_] = 
  ParametricPlot3D[{r*Cos[t], r*Sin[t], -.1}, {t, 0, 2 Pi}, 
   PlotStyle -> Brown];
Graphics3D[{Pink, 
  MapThread[
   GeometricTransformation[#1, 
     TranslationTransform[#2]@*
      RotationTransform[π/3, {0, 0, 1}]] &, {regs, pts}], 
  Boxed -> False, ViewPoint -> {1, 1, 1}, 
  ViewProjection -> "Orthographic", circle3[r][[1]], 
  MapThread[
   Inset[Style[NumberForm[N@#1, 2], Blue, 
      20], #2 + {0, 0, #1} + {0, 0, .8}] &, {values, pts}]}, 
 Boxed -> False]

enter image description here

Original

values = {1, 2, 3, 4};
values = Reverse@values;
n = Length@values;
regs = ArrayMesh[{ConstantArray[{1}, #]}] & /@ values;
r = n;
pts = PadRight[#, 3] & /@ CirclePoints[{r, Pi}, n];
circle3[r_] = 
  ParametricPlot3D[{r*Cos[t], r*Sin[t], -.1}, {t, 0, 2 Pi}, 
   PlotStyle -> Brown];
Graphics3D[{Pink, 
  MapThread[
   GeometricTransformation[#1, 
     TranslationTransform[#2]@*RotationTransform[π/3, {0, 0, 1}]@*
      TranslationTransform[-{1/2, 1/2, 0}]] &, {regs, pts}], 
  Boxed -> False, ViewPoint -> {1, 1, 1}, 
  ViewProjection -> "Orthographic", circle3[r][[1]], 
  MapThread[
   Inset[Style[#1, Blue, 20], #2 + {0, 0, #1} + {0, 0, 1}] &, {values,
     pts}]}, Boxed -> False]

enter image description here

$\endgroup$
7
  • $\begingroup$ Thank you very much! This is a great solution! But Unfortunately, this function cannot work with fractions and negative numbers. And there is also no function that can be used to define the size (height and width) of the stones. I think, such a function would be very great for large sets with large numbers, otherwise it will go immeasurably in the high and breaks the frame. Maybe we can optimize that a bit, then it would be perfect! Of course, only if you have the desire and the time to do that. Thank you again for your efforts, i really appreciate that! $\endgroup$
    – Karl560
    Aug 22, 2022 at 3:55
  • $\begingroup$ @Karl560 Re-write the regs by using RegionProduct can easy to do this for any real numbers, but I have not computer here :) $\endgroup$
    – cvgmt
    Aug 22, 2022 at 4:22
  • $\begingroup$ Ok, I will try it, but I don' t think I can do it, because my skills are too low. But if you should decide to finish the whole thing, then I would be happy to honor your work. I hope that wasn't inappropriate, but I don' t want to give the impression that I want something for free. The entire thing should help to quickly and efficiently detect anomalies in a dataset with the naked eye. And this type of diagram works very well for that, see the attached image, you can see the anomalies immediately. s20.directupload.net/images/220822/iko97x6p.jpg $\endgroup$
    – Karl560
    Aug 22, 2022 at 5:21
  • $\begingroup$ @Karl560 I will updated the code later after I get home. $\endgroup$
    – cvgmt
    Aug 22, 2022 at 5:29
  • $\begingroup$ That's very kind of you. Thank you very much! $\endgroup$
    – Karl560
    Aug 22, 2022 at 5:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.