Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to draw the following picture in Mathematica as shown below with distinct color for each section.

enter image description here

share|improve this question
    
Well, did you try anything and, if yes, where did you get stuck? –  acl Jul 16 at 11:25
1  
I used this code: Plot3D[-1/4 x^3, {x, -20, 20}, {y, 0, 30}, ColorFunction -> Function[{x}, Piecewise[{{Red, -20 <= x < -10}, {Orange, -10 <= x < 0}, {Yellow, 0 <= x <= 20}}]], PlotStyle -> Thick, ColorFunctionScaling -> False] –  MathMan Jul 16 at 11:32

2 Answers 2

up vote 8 down vote accepted

Try using MeshShading:

Plot3D[
 -(x - 12.5)^3,
 {x, 0, 25},
 {y, 0, 20},
 MeshShading -> {Table[Hue[x], {x, 0, 1, 1/16}]}
 ]

The Table part generates sixteen different colors from the Hue color function. I did this because the image in this case had sixteen rows. If there are more rows than colors the colors will be reused cyclically.

Mesh shading

share|improve this answer
    
Thanks you. and about dotted grid lines in background? –  MathMan Jul 16 at 12:13
    
@MathMan I was away, it seems Mr.Wizard solved it in the meantime :) –  Pickett Jul 16 at 14:32

Building on Pickett's answer with a few more Options:

pl = Plot3D[-(x - 12.5)^3, {x, 0, 25}, {y, 0, 20}, 
 MeshShading -> {Table[Hue[x], {x, 0, 1, 1/16}]},
 BoxRatios -> 1, 
 Boxed -> False,
 FaceGrids -> {{0, 1, 0}, {-1, 0, 0}, {0, 0, -1}}, 
 FaceGridsStyle -> Directive[Thick, Gray, Dotted]
]

enter image description here

It's not perfect but hopefully it points you in a useful direction.


An example for the legend was requested. One can use Inset to place a Graphics (or other) object in a 3D plot. As a rough illustration:

rec = Graphics[{Green, EdgeForm[Thick], Rectangle[{0, 0}, {50, 20}]}, 
   ImageSize -> {50, 20}, PlotRangePadding -> 0];

lg = Framed[Row[{rec, Style["S", 18]}]];

Show[pl, Epilog -> Inset[lg, Scaled[{0.8, 0.8}]]]

enter image description here

share|improve this answer
    
I copied the wrong code for that particular graphic. Now corrected. Sorry for any confusion. –  Mr.Wizard Jul 16 at 13:16
    
and about the Legend? –  MathMan Jul 16 at 16:48
    
@MathMan Which version of Mathematica are you using? –  Mr.Wizard Jul 16 at 23:44
    
I am using Mathematica 7 –  MathMan Jul 19 at 11:07
    
@MathMan See update. –  Mr.Wizard Jul 19 at 11:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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