I have:

Manipulate[

If[reflection, Plot[{-func}, {x, -3, 3},

PlotStyle -> Red,

PlotRange -> {{-3, 3}, {-3, 3}},

GridLines -> Automatic,

PlotLabel -> StringForm[“f(x) = “”, -func]],

Plot[{func}, {x, -3, 3},

PlotStyle -> Blue,

PlotRange -> {{-3, 3}, {-3, 3}},

GridLines -> Automatic,

PlotLabel -> StringForm[“f(x) = “”, func]]],

{func, {Sqrt[x], Abs[x], x^2, x^3}},

{reflection, {False, True}}]

I’d like to make my plot label red when reflection is true and blue if reflection is false. How do you add color to StringForm[“f(x) = “”, func]?

=================

=================

1 Answer

1

=================

You can use LabelStyle -> Directive[Bold, Red] and

LabelStyle -> Directive[Bold, Blue]

Manipulate[

If[reflection,

Plot[{-func}, {x, -3, 3}, PlotStyle -> Red,

PlotRange -> {{-3, 3}, {-3, 3}}, GridLines -> Automatic,

PlotLabel -> StringForm[“f(x) = “”, -func],

LabelStyle -> Directive[Bold, Red]],

Plot[{func}, {x, -3, 3}, PlotStyle -> Blue,

PlotRange -> {{-3, 3}, {-3, 3}}, GridLines -> Automatic,

PlotLabel -> StringForm[“f(x) = “”, func],

LabelStyle -> Directive[Bold, Blue]]], {func, {Sqrt[x], Abs[x],

x^2, x^3}}, {reflection, {False, True}}]

EDIT

Per request, changing the label and not the ticks can be done:

Individually styled labels can be used with LabelStyle and have higher

priority

-a mathematica help page

So we change the label directive to one color and wrap the label in a style, which is given priority:

If[reflection,

Plot[{-func}, {x, -3, 3}, PlotStyle -> Cyan,

PlotRange -> {{-3, 3}, {-3, 3}}, GridLines -> Automatic,

PlotLabel -> Style[StringForm[“f(x) = “”, -func], Red],

LabelStyle -> Directive[Bold, Magenta]],

Plot[{func}, {x, -3, 3},

PlotStyle -> Cyan, PlotRange -> {{-3, 3}, {-3, 3}},

GridLines -> Automatic,

PlotLabel -> Style[StringForm[“f(x) = “”, -func], Blue],

LabelStyle -> Directive[Bold, Magenta]]], {func, {Sqrt[x], Abs[x],

x^2, x^3}}, {reflection, {False, True}}]

Very easy solution. But I think I would like just my plot label to change colors and note the ticks. But thanks for a very nice easy answer.

– David

Feb 9 at 18:03

@David also possible! check out the edits- I used outlandish colors to make each part obvious.

– Peter Roberge

Feb 9 at 18:19

Thanks. These are some very nice options.

– David

Feb 10 at 16:28