How can I draw a plot like this one? I want to be able to specify the x-axis, y-axis, and z-axis ticks and the number of bars in the plot.

enter image description here

  • 2
    $\begingroup$ This looks like a Mathematica generated plot. Where did you find it? Can you supply a link? $\endgroup$ – m_goldberg Feb 25 '13 at 13:30
  • $\begingroup$ I got it from google. $\endgroup$ – niren Feb 25 '13 at 13:57
  • $\begingroup$ Please post the link anyway. Many students had come in the past with homework plots to be reproduced. Not your case, surely $\endgroup$ – Dr. belisarius Feb 25 '13 at 14:07
  • $\begingroup$ A hint f[x_, y_, n_] := Total@Flatten@ Table[UnitBox[(x - a)/100, (y - b)/100], {a, 200, n 200, 200}, {b, 200, n 200, 200}]; $\endgroup$ – Dr. belisarius Feb 25 '13 at 14:30
  • $\begingroup$ "I got it from google" - perhaps there's some data on the same page that might be useful... $\endgroup$ – cormullion Feb 25 '13 at 18:31

Since the Google reference isn't forthcoming, it's probably easier to fake it like this:

i = Blur[ 
        Table[Rectangle[{x, y}, 20 + {x, y}], 
         {x, 0, 100, 35}, 
         {y, 0, 100, 35}]}, 
       PlotRangePadding -> 15, 
       Background -> White], 
      ImageSize -> 100],
xticks = Transpose[{Range[0, 100, 20], Range[0, 1000, 200]}];
yticks = Transpose[{Range[0, 100, 20], Range[0, 1000, 200]}];
zticks = Transpose[{Range[0, 1, .2], Range[0, 25, 5]}];
ListPlot3D[ImageData[i] /. {x_, y_, z_} -> 1 - z, 
   Mesh -> 20, 
   Ticks -> {xticks, yticks, zticks}, 
   PlotRangePadding -> 0.1]

fake image

  • $\begingroup$ Thank you for your answer. I got another problem not only with this Plot, its with all the try that i made for the same plot. When i Deploy the code in CDFDeploy, its working fine but i couldn't rotate the plot. $\endgroup$ – niren Feb 27 '13 at 6:42
  • $\begingroup$ I have found myself the answer for CDFDeploy problem. I have resolved the problem using Manipulate. $\endgroup$ – niren Feb 27 '13 at 11:05
  • $\begingroup$ I have customized the number of bars i want on the plot, But i couldn't customize the height of each bar, Because in your code you get the data from image which range between 0 and 1. I want the height of some bar to be 20 and some to be 25 and so on. $\endgroup$ – niren Feb 27 '13 at 11:20
  • 4
    $\begingroup$ @niren I think you should probably first of all specify/supply the 'data' that you want to plot, then people here on this site can help you plot it in different ways. I just used an image because there was no data. To change the heights of the bars in my example, I would make some of the squares less black ...:) Perhaps you really want to construct a 3D object from Cuboids? If you put more effort into your question, any answers you get will be more relevant and useful to you. $\endgroup$ – cormullion Feb 27 '13 at 11:39

You could do something similar to the given example using Histogram3D, which comes with many options.

You need to specify the data you have in hand in your question. If you really need a flat top, as you show in your example, you could use the function UniformDistribution as the input for Histogram3D.

  • $\begingroup$ Thank you for your reply, but Histogram3D doesn't give me the plot the way i want. $\endgroup$ – niren Feb 26 '13 at 5:54
  • $\begingroup$ What's the problem with Histogram3D? Do you want a gap between the colummns? $\endgroup$ – fcpenha Feb 26 '13 at 11:42

You really need to specify better what you want. In case you want to draw 3D rectangular columns with some gap in between, the following code would do the work:

    max = 10;
    step = max;
    factor = 2*max;

    DiscretePlot3D[ factor * PDF[ 
     UniformDistribution[{-max, max}], {x, y} ], 
     {x, -max, max, step}, {y,-max, max, step},
     ExtentSize -> max/2 ]
  • $\begingroup$ Hello there! I just wanted to point out that you can easily edit your previous answer by clicking the edit link and add this (and other updates) to it instead of serially posting answers :) $\endgroup$ – rm -rf Feb 26 '13 at 14:26

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.