7
$\begingroup$

I'm using BarChart3D to plot matrices. The code I wrote used to work fine until Mathematica 11.

For some reason, negative values of the matrix appear very dark on the plot, whereas it didn't before. It looks like, rendering speaking, the face normals switch direction when the bars are negative, and the lighting is thus reversed.

Example code:

BarChart3D[Table[1 Exp[-(((x - 4)^2 + (y - 4)^2)/8)] (x - 4), {x, 1, 8}, {y, 1,8}], ChartLayout -> "Grid", ChartElementFunction -> "Cube", Method ->{"Canvas" -> None}, ColorFunctionScaling -> False,ColorFunction -> (Blend[{{-1, Red}, {0, White}, {1, Red}}, #] &),BarSpacing -> {0, 0}, ViewPoint -> {-6, -9, 4.2},ViewVertical -> {0, 0, 1}, ImageSize -> 850]

Comparison between 11.01 and 10.4:

Comparison I found some ways around it by fiddling with Lighting->{...}, but it never looks as good as it used to.

Any idea ?

Thanks !

$\endgroup$
  • $\begingroup$ Welcome. Wait a few minutes that one of our users will leave some tips. $\endgroup$ – LCarvalho Nov 22 '16 at 19:30
  • $\begingroup$ Quite strange that all the other chart functions from ChartElementData["BarChart3D"], such as FadingCube, work fine. $\endgroup$ – Stitch Nov 22 '16 at 21:37
7
$\begingroup$

You are correct about the face normals switching direction, it seems that in version 11 we must be careful that pt1 is lower than pt2 in Cuboid[pt1, pt2]. Cuboids may appear inside-out if this is not the case. Example:

Graphics3D[{FaceForm[Red, Green],
  Cuboid[{0, 0, 0}, {1, 1, 1}], 
  Cuboid[{0, 0, 0}, {1, 1, -1}]}]

enter image description here

The bar chart can therefore be fixed by post-processing the CuboidBox boxes to meet the new requirement.

fix = CuboidBox[data__] :> RuleCondition[CuboidBox @@ Transpose[Sort /@ Transpose[{data}]]]

BarChart3D[
  Table[1 Exp[-(((x - 4)^2 + (y - 4)^2)/8)] (x - 4), {x, 1, 8}, {y, 1, 8}],
  ChartLayout -> "Grid", ChartElementFunction -> "Cube", 
  Method -> {"Canvas" -> None}, ColorFunctionScaling -> False, 
  ColorFunction -> (Blend[{{-1, Red}, {0, White}, {1, Red}}, #] &), 
  BarSpacing -> {0, 0}, ViewPoint -> {-6, -9, 4.2}, 
  ViewVertical -> {0, 0, 1}, ImageSize -> 850] /. fix

enter image description here

$\endgroup$
  • $\begingroup$ Awesome, thanks a lot ! $\endgroup$ – Valérian Thiel Nov 23 '16 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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