8
$\begingroup$

I have plotted a sine function where the period is varied. I have included my code below.

tab = Table[Sin[a x], {a, 1, 2, 0.25}]; Plot[tab , {x, 0, 2 \[Pi]}, Frame -> True] 

enter image description here

To help identify which curve corresponds to which value of a, I thought to create a colorbar that runs from 1 to 2 (the color of the curves would need to change). Is this possible using Plot? This is the best way that I can think of to help identify each curve, especially if the number of curves is increased.

$\endgroup$
1

5 Answers 5

10
$\begingroup$
Clear["Global`*"]; tab = Table[Sin[a x], {a, 1, 2, 0.25}]; Plot[tab, {x, 0, 2 π} , Frame -> True , PlotStyle -> (ColorData["Rainbow"][Rescale[#, {1, 2}]] & /@ Range[1, 2, 0.25]) , PlotLegends -> Placed[BarLegend[{"Rainbow", {1, 2}}], After] ] 

enter image description here


Addendum:

To include Tooltips:

Clear["Global`*"]; tab = Table[Sin[a x], {a, 1, 2, 0.25}]; labels = "a=" <> ToString@NumberForm[#, {3, 2}] & /@ Range[1, 2, 0.25]; items = Transpose[{tab, labels}] Plot[Evaluate[Tooltip[First@#, Last@#] & /@ items], {x, 0, 2 π} , Frame -> True , PlotStyle -> (ColorData["Rainbow"][Rescale[#, {1, 2}]] & /@ Range[1, 2, 0.25]) , PlotLegends -> Placed[BarLegend[{"Rainbow", {1, 2}}, LegendLabel -> "a"], After ] ] 
$\endgroup$
10
$\begingroup$

Maybe this is what you're looking for?

tab = Table[Sin[a x], {a, 1, 2, 0.25}]; Plot[tab, {x, 0, 2 \[Pi]}, Frame -> True, PlotLegends -> "Expressions"] 

enter image description here

Edit:

 Plot[tab, {x, 0, 2 \[Pi]}, Frame -> True, PlotLegends -> SwatchLegend[ColorData[97, "ColorList"], "a=" <> ToString@NumberForm[#, {3, 2}] & /@ Range[1, 2, 0.25], LegendLabel -> "sin(ax)"]] 

enter image description here

$\endgroup$
7
$\begingroup$
tab = Table[Sin[a x], {a, 1, 2, 0.25}]; 

Using PlotLabels and Tooltip

Plot[Tooltip @ tab, {x, 0, 2.1 Pi}, Frame -> True, FrameTicks -> {{Automatic, None}, {Range[0, 2 Pi, Pi/2], None}}, GridLines -> {Range[0, 2 Pi, Pi/2], Automatic}, PlotLabels -> "Expressions"] 

enter image description here

$\endgroup$
6
$\begingroup$
$Version (* "14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)" *) Clear["Global`*"] tab = Table[Sin[a x], {a, 1, 2, 0.25}]; 

To facilitate visually identifying an individual curve, use Manipulate

Manipulate[ Plot[Evaluate@Tooltip[tab], {x, 0, 2 \[Pi]}, Frame -> True, PlotStyle -> ({ColorData["Rainbow"][# - 1], Thickness[If[hl == #, 0.009, 0.005]]} & /@ Range[1, 2, 0.25]), PlotLegends -> BarLegend[{"Rainbow", {1, 2}}]], {{hl, None, "highlight"}, Prepend[Range[1, 2, 0.25], None], ControlType -> SetterBar}] 

enter image description here

$\endgroup$
1
$\begingroup$

Another method to "help identify which curve corresponds to which value of a" is to use one of the many PlotHighlighting options: Mousing over or pointing at one of the curves highlights the plot at the given position.

PlotHighlighting was introduced in V 13.1

tab = Table[Sin[a x], {a, 1, 2, 0.25}]; Plot[Evaluate @ tab, {x, 0, 2.1 Pi}, Axes -> False, Frame -> True, FrameTicks -> {{Automatic, None}, {Range[0, 2 Pi, Pi/2], None}}, PlotHighlighting -> "Dropline", PlotLabels -> "Expressions", PlotStyle -> Thickness[0.004]] 

enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.