PlotLegends doesn't work on Plot3D-V8.0.0

1

I am trying to plot in 3D and I need to use PlotLegend. My code is

Needs["PlotLegends`"]
Evaluate[PlotLegends]
Plot3D[Tanh[H/T], {T, 0, 300}, {H, 0.001, 1}, 
PlotLabel -> 
  Style[Framed[
    "Energy Dependance on Magnetic Field H and Absolute Temperature \
T"], 13, Red, Background -> Lighter[LightYellow]], 
 Background -> LightGray, 
 ColorFunction -> Function[{x, y, z}, Hue[.65 (1 - z)]], 
 AxesLabel -> {T[kelvin], H[tesla]}, BoundaryStyle -> Thick, 
 ClippingStyle -> Opacity[0.5], Mesh -> Full, 
 PlotLegends -> Automatic]

While I use Needs["PlotLegends`"] I don't seem to be able to plot a legend. I get an error saying

Plot3D::optx: Unknown option PlotLegends in Plot3D[...]

How can this be fixed?

Thanos

Posted 2012-12-19T16:58:03.997

Reputation: 921

2This is an example from the documentation on how to use PlotLegend: ShowLegend[ Plot3D[Sin[x y], {x, 0, \[Pi]}, {y, 0, \[Pi]}, ColorFunction -> "Rainbow"], {ColorData["Rainbow"][1 - #1] &, 10, " 1", "-1", LegendPosition -> {1.1, -0.4}}] – VLC – 2012-12-19T17:28:23.460

Answers

2

I returned to the problem after reading the comments above. In version 8, the PlotLegends -> option works for Plot[] but not for Plot3D[]. For Plot3D, you will have to use ShowLegend[], as demonstrated below:

ShowLegend[
 Plot3D[Tanh[H/T], {T, 0, 300}, {H, 0.001, 1}, 
  PlotLabel -> 
   Style[Framed[
     "Energy Dependance on Magnetic Field H and Absolute Temperature \
T"], 13, Red, Background -> Lighter[LightYellow]],(*Background->
  LightGray,*)ColorFunction -> Function[{x, y, z}, Hue[.65 (1 - z)]], 
  AxesLabel -> {T[kelvin], H[tesla]}, BoundaryStyle -> Thick, 
  ClippingStyle -> Opacity[0.5], 
  Mesh -> Full], {{{Graphics[{White, Circle[{0, 0}, 0]}], Tanh[H/T]}},
   LegendPosition -> {1.1, -.4}}]

This becomes simpler in version 9, where you can use PlotLegends-> if you like

Plot3D[Tanh[H/T], {T, 0, 300}, {H, 0.001, 1}, 
 PlotLabel -> 
  Style[Framed[
    "Energy Dependance on Magnetic Field H and Absolute Temperature \
T"], 13, Red, 
   Background -> Lighter[LightYellow]],(*Background->LightGray,*)
 ColorFunction -> Function[{x, y, z}, Hue[.65 (1 - z)]], 
 AxesLabel -> {T[kelvin], H[tesla]}, BoundaryStyle -> Thick, 
 ClippingStyle -> Opacity[0.5], Mesh -> Full, 
 PlotLegends -> 
  SwatchLegend["Expressions"]]

Michael Stern

Posted 2012-12-19T16:58:03.997

Reputation: 4 380

I tried your solution but it is still not working. I keep getting the error message that Plot3D::optx: Unknown option PlotLegends in Plot3D[...] – Thanos – 2012-12-19T19:17:04.567

Try the revised code above. – Michael Stern – 2012-12-19T22:20:09.297

It's working!!! Thank you very much!!! However I noticed something weird... I cannot rotate the plot...Is this suppossed to happen? – Thanos – 2012-12-20T17:14:40.637

Do you mean click-and-drag rotation, or manually specifying the angle in the Plot3D command? p.s. do a brother a favor and accept my answer above? – Michael Stern – 2012-12-21T19:08:05.923