I'm looking to draw only one half of an axis in ContourPlot3D, mainly because I don't wan't the axis lines to be where the interesting stuff happens (intersection of two surfaces), but I do want to show where the axes are. This is my code so far:

ContourPlot3D[{y == x^2, z == x^3}, {x, -3, 3}, {y, -5, 5}, {z, -10, 10},
   AxesLabel -> Automatic, Boxed -> False, AxesOrigin -> {0, 0, 0},
   Mesh -> None, ContourStyle -> Opacity[0.3]]

This is the result it produces:

enter image description here

I would like only half of each axis to appear on the graph. I already dug through the documentation, but it seems I can only turn the axes on or off completely, no partial option. Thanks in advance for any help.

  • $\begingroup$ I think it's not possible if you use the built-in axes. Axes are infinite and always span the complete bounding box. You'll have to draw your own axes. The CustomTicks package will be very helpful in generating your own tick marks. $\endgroup$ – Szabolcs Jan 10 '14 at 1:09
  • $\begingroup$ I believe removing axes altogether and adding your own as Epilog shouldn't be hard. $\endgroup$ – carlosayam Jan 10 '14 at 1:54
  • $\begingroup$ Yes, not easy as a general problem - approachable for a particular case. It depends on how much effort you want to put in your graphic, I believe. OTOH, I haven't checked CustomTicks; if someone has a free solution that fits the bill, go for it :) $\endgroup$ – carlosayam Jan 10 '14 at 2:02
  • $\begingroup$ I'm just throwing it in here because I wonder this myself. In the docs for FullGraphics it says "FullGraphics generates explicit graphics primitives for objects specified by options such as Axes, Ticks, etc." -- is there perhaps a way to extract the primitives used to draw the axes? In that case it should be straightforward to remove half of it. $\endgroup$ – C. E. Jan 10 '14 at 2:03

Possible workaround with manual dashing

 ContourPlot3D[{y == x^2, z == x^3}, {x, -3, 3}, {y, -5, 5}, {z, -10, 10},
  Boxed -> False, AxesOrigin -> {0, 0, 0}, Mesh -> None, ContourStyle -> Opacity[0.5], 
  Ticks -> {-Range[3], -Range[5], Range[0, 10, 2]}, 
  AxesStyle -> {Dashing[{0.28, 0.3}], Dashing[{0.3, 0.5}], Dashing[{0, 0.25, 0.5}]}, 
  TicksStyle -> Dashing[{}]],
 Graphics3D[{Text[x, {-3.4, 0, 0}, BaseStyle -> Large], 
  Text[y, {0, -5.5, 0}, BaseStyle -> Large], 
  Text[z, {0, 0, 11.5}, BaseStyle -> Large]}]

enter image description here

| improve this answer | |
  • $\begingroup$ Alright, now how could I put labels on those axes (preferably at/near the ends)? $\endgroup$ – Jānis Lazovskis Jan 10 '14 at 2:34
  • $\begingroup$ @JimboBimbo You can add Text with explicit positions, see my update. $\endgroup$ – ybeltukov Jan 10 '14 at 2:46
  • $\begingroup$ Ok, that does indeed help. But this solution is odd, because when I rotate the graph, the lengths of the axes seem to change arbitrarily, becoming longer and shorter. I'm not sure if this is a problem with my machine, or something else. They appear in most of the desired side, but shrink and stretch on the other side as I turn it around. $\endgroup$ – Jānis Lazovskis Jan 10 '14 at 3:02
  • $\begingroup$ @JimboBimbo Yes, you need to change the dashing parameters for different points of view. It is just a workaround. Strictly speaking you need a package like CustomTicks as Szabolcs wrote in comments. $\endgroup$ – ybeltukov Jan 10 '14 at 3:07

It is not by chance that ContourPlot3D defaults to Boxed->True. It leaves the surfaces away from the axes.

You can then add other axes or wherever you like. Below, the x and y axes are projected onto the x y plane. I find this a bit helpful for conveying that (0,0,0) is somewhere in the center of the box.

Show[ContourPlot3D[{y == x^2, z == x^3}, {x, -3, 3}, {y, -5, 
   5}, {z, -10, 10},
  BaseStyle -> 16, BoxStyle -> Directive[Dashed, GrayLevel[.25]], 
  AxesLabel -> Automatic,
  Mesh -> None, ContourStyle -> Opacity[0.3]],
 Graphics3D[{Thickness[.005], Dashed, Blue, 
   Line[{{-3, 0, -10}, {5, 0, -10}}], 
   Line[{{0, -5, -10}, {0, 5, -10}}]}]]

enter image description here

| improve this answer | |
  • 1
    $\begingroup$ Ok, but is it possible to add ticks and numbers to those lines so they look like axes? $\endgroup$ – Jānis Lazovskis Jan 10 '14 at 2:15
  • $\begingroup$ You can easily add ticks and numbers using Table. $\endgroup$ – DavidC Jan 10 '14 at 3:25

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.