3
$\begingroup$

I have drawn the set of power function according to the following codes.

Plot[{x^(-1), x^0, Root[#^3 - x &, 1], x^(1/2), Root[#^3 - x^2 &, 1], 
  Root[#^8 - x^7 &, 2], x, x^2, x^3}, {x, -2, 5}, AspectRatio -> 1, 
 PlotLabels -> Automatic, Axes -> True, 
 AxesStyle -> Arrowheads[{0.0, 0.04}], AxesLabel -> {x, y}, 
 ImageSize -> 500, PlotHighlighting -> "XSlice"]

the result is this:

enter image description here

How to modify the labels of functions to this as show in the following picture?

enter image description here

$\endgroup$

2 Answers 2

2
$\begingroup$

For plots with many possible functions, use a TogglerBar to enable selectively showing or hiding the individual functions.

$Version

(* "13.3.1 for Mac OS X ARM (64-bit) (July 24, 2023)" *)

Clear["Global`*"]

labels =
  {x^("-1"), x^"0", x^("1/3"), x^("1/2"), x^("2/3"), x^("7/8"), x, x^2, x^3} //
   ToRadicals;

funcs = labels /. str_String :> ToExpression[str];

colors = ColorData[97, "ColorList"];

Display

Manipulate[
 index = Sort@index;
 Plot[Evaluate@(Tooltip /@ funcs[[index]]), {x, -2, 5},
  PlotRange -> {{-2, 5}, {-5.1, 8.1}},
  PlotRangePadding -> Scaled[.05],
  AspectRatio -> 1,
  PlotStyle -> colors[[index]],
  PlotLabels -> labels[[index]],
  Axes -> True,
  AxesStyle -> Arrowheads[{0.0, 0.04}],
  AxesLabel -> {x, y},
  ImageSize -> 500,
  PlotHighlighting -> hilite],
 Row[{
   Control[{{index, Range@Length@funcs, "functions"},
     Thread[(Range@Length@funcs) -> labels],
     ControlType -> TogglerBar}],
   Spacer[20],
   Control[{{hilite, "XSlice", "HighLight"},
     {"XSlice", "YSlice", "XYDroplines", None}}]}]]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thank you very much for providing the code! This is very practical. There are several issues: 1. The function x ^ (1/3) is an odd function, and there are images in the first and third quadrants, but after running the code, there are only images in the first quadrant. 2. The function x ^ (2/3) is an even function, and there are images in both the first and second quadrants, but after running the code, there are only images in the first quadrant. $\endgroup$
    – csn899
    Commented Jan 2 at 0:14
  • 1
    $\begingroup$ You have a misunderstanding of roots. (-1)^(1/3) // N is complex as is (-1)^(2/3) // N. You presumably want CubeRoot[x] instead of x^(1/3) (look at Reduce[{x^(1/3) == CubeRoot[x], x \[Element] Reals}, x]) and (x^2)^(1/3) instead of x^(2/3) (look at Reduce[{x^(2/3) == (x^2)^(1/3), x \[Element] Reals}, x]) $\endgroup$
    – Bob Hanlon
    Commented Jan 2 at 3:03
6
$\begingroup$

Is the following sufficient? If yes, then you want to have a look at ToRadicals

forplot = 
  ToRadicals[{x^(-1), x^0, Root[#^3 - x &, 1], x^(1/2), 
    Root[#^3 - x^2 &, 1], Root[#^8 - x^7 &, 2], x, x^2, x^3}];

and then

Plot[{forplot}, {x, -2, 5}, AspectRatio -> 1, PlotLabels -> Automatic,
  Axes -> True, AxesStyle -> Arrowheads[{0.0, 0.04}], 
 AxesLabel -> {x, y}, ImageSize -> 500]

plot

Edit: the command PlotHighlighting is missing because I do not have v13.3 but I don't think it is going to cause any conflicts.

$\endgroup$
2
  • 2
    $\begingroup$ (+1) Happy New Year, mate! Thanks for all the fun with the ten ways to code something. :-) $\endgroup$ Commented Jan 1 at 2:45
  • 2
    $\begingroup$ @E.Chan-López Happy new year! Best wishes and many 10-ways (and more) to code one thing :-) $\endgroup$
    – bmf
    Commented Jan 1 at 2:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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