3

Consider the following :

cAxes = {{{0, 0, 0}, {0, 0, 1}}, {{0, 0, 0}, {0, 1, 0}}, {{0, 0,0}, {1, 0, 0}}};

Graphics3D[{Line /@ cAxes}, Boxed -> False]

enter image description here

How can Style differently the 3 lines ?

500
  • 6,509
  • 8
  • 46
  • 80

5 Answers5

6

The answer above are good, but I want to show some alternatives.

I show that it is possible to use Style for this, and that Tube is an interesting alternative to Line.

cAxes = {{{0, 0, 0}, {0, 0, 1}}, {{0, 0, 0}, {0, 1, 0}}, {{0, 0, 
     0}, {1, 0, 0}}};

tubes = Tube@# ~Style~ #2 & ~MapThread~ {cAxes, {Red, Green, Blue}};

Graphics3D[tubes, Boxed -> False]

enter image description here

Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
  • Could I send you something a little demo I am preparing ? I am struggling with some Graphics, but the code is to long ! – 500 Nov 14 '11 at 17:54
  • 1
    @500 Yes, go ahead. I should be able to spend some time on it today. – Mr.Wizard Nov 14 '11 at 20:30
  • +1 for infix notation **~MapThread~**, that makes it "look" much more like the way that it works. – Daniel Chisholm Nov 15 '11 at 12:17
  • @Daniel, thank you. I like to use infix notation a lot. It has the significant advantage of letting me quickly know that the function is handling exactly two arguments, much as `@` or `//` indicate a single argument. I would actually write the Style function above as `Tube@# ~Style~ #2 &` but I feared that others unfamiliar with infix would find it confusing. Since this is not the first time I have received positive comments about infix however, I am going to stop worrying and use it liberally. – Mr.Wizard Nov 15 '11 at 21:08
4

Here's an example:

colors = {Red, Green, Blue};
style = {Dashed, DotDashed, Dotted};
cAxes = {{{0, 0, 0}, {0, 0, 1}}, {{0, 0, 0}, {0, 1, 0}}, {{0, 0, 
     0}, {1, 0, 0}}};
Graphics3D[{#1, #2, Line@#3} & @@@ Transpose@{colors, style, cAxes}, 
 Boxed -> False]

enter image description here

abcd
  • 41,765
  • 7
  • 81
  • 98
4

Also remember that you can do the same with Plot3D if you need it:

colors = {Red, Green, Blue};
style = {Dashed, DotDashed, Dotted};
Plot3D[{}, {x, 0, 10}, {y, 0, 10}, 
 AxesLabel -> {x, y, z}, 
 AxesStyle -> Directive /@ Transpose@{colors, style}, 
 Boxed     -> False]
Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190
4

You could also use MapThread:

cAxes = {{{0, 0, 0}, {0, 0, 1}}, {{0, 0, 0}, {0, 1, 0}}, {{0, 0, 0}, {1, 0, 0}}};

Graphics3D[{
   MapThread[{#1, Line[#2]} &, {{Red, Blue, Green}, cAxes}]
   }, Boxed -> False]
Brett Champion
  • 8,497
  • 1
  • 27
  • 44
3

Untested (I don't have access to Mathematica right now):

Graphics3D[Transpose@{{Red, Green, Blue}, Line /@ cAxes}, Boxed -> False]
Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
celtschk
  • 19,311
  • 3
  • 39
  • 64
  • celtschk, congratulations on being the top new user this month as of today! http://stackexchange.com/leagues/1/month/stackoverflow – Mr.Wizard Nov 15 '11 at 22:37
  • 1
    @Mr.Wizard: Thanks for notifying me about this. And also thanks for fixing the mistake in my code. – celtschk Nov 15 '11 at 22:45