3
$\begingroup$

Hello fellow Mathematica users! I am trying to plot a barchart 3d plot for some data. However, I am facing issues with colorscheme. For example consider the following code:

dta = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};


BarChart3D[dta, ChartLayout -> "Grid", ViewPoint -> {3.33, -8.26, 5.36}]

Ifbar chart you run the above simplistic code, you will see a 3*3 bar chart. However, in this plot, all the bars in the column have the same color. But I need same color bars in the row. Can you suggest a way such that I have same color bars in the row?

$\endgroup$
3
  • $\begingroup$ Using Transpose :) : BarChart3D[Reverse /@ Transpose[dta], ChartLayout -> "Grid", ViewPoint -> {3.33, -8.26, 5.36}]. More seriously, 1) I cannot find documentation describing ChartLayout -> "Grid", and 2) using ColorFunction might be a possible way. $\endgroup$ Jun 12, 2023 at 13:43
  • $\begingroup$ Thanks for the suggestion. @AntonAntonov, but this code still not generates plot with same color bars horizontally. $\endgroup$ Jun 12, 2023 at 13:50
  • $\begingroup$ It does -- did you try it? $\endgroup$ Jun 12, 2023 at 13:58

2 Answers 2

5
$\begingroup$
BarChart3D[dta, 
 ChartLayout -> "Grid", 
 ViewPoint -> {3.33, -8.26, 5.36}, 
 ChartStyle -> {Automatic, None}]

enter image description here

To remove the background panels use "Canvas" -> False :

BarChart3D[dta, 
 ChartLayout -> "Grid", 
 ViewPoint -> {3.33, -8.26, 5.36}, 
 ChartStyle -> {Automatic, None}, 
 "Canvas" -> False]

enter image description here

$\endgroup$
2
  • $\begingroup$ Many thanks @kglr, it is very simple and useful. $\endgroup$ Jun 12, 2023 at 14:30
  • $\begingroup$ @physicsgeek, my pleasure. Thank you for the accept. $\endgroup$
    – kglr
    Jun 12, 2023 at 14:31
2
$\begingroup$

Here is a possible, not very good, solution via Reverse /@ Transpose[...]:

gr = BarChart3D[Reverse /@ Transpose[dta], Axes -> True, 
 FaceGrids -> {{-1, 0, 0}}, ChartLayout -> "Grid", Ticks -> All, 
 ViewPoint->
  List[8.90170545374032`, 3.8424205491683088`, 3.741048561323293`], 
 Boxed -> True]

enter image description here

The panels can be removed with Rest :

Rest /@ gr
$\endgroup$
2
  • $\begingroup$ Thanks again. Yeah, it works. $\endgroup$ Jun 12, 2023 at 14:07
  • $\begingroup$ No problem! But there should be a more streamlined and better looking solution. $\endgroup$ Jun 12, 2023 at 14:13

Your Answer

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

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