4
$\begingroup$

I want to graph the first polynomials of Chebyshev almost like the graph of wikipedia

https://en.wikipedia.org/wiki/File:Chebyshev_Polynomials_of_the_First_Kind.svg

I have tried it this way

Plot[Evaluate[Table[ChebyshevT[n - 1, x], {n, 5}]], {x, 0, 1}, 
PlotStyle -> {Blue, Orange, Green, Magenta, Purple}, 
PlotTheme -> "Scientific"]
LineLegend[{Blue, Orange, Green, Magenta, 
Purple},{"T0","T1","T2","T3","T4"}]

I can't put the legends on top of the graphic like in wikipedia or at least put them in a single line.

I have tried with the Show command but I have not succeeded. I appreciate any help.

$\endgroup$
  • 1
    $\begingroup$ Have you seen that the source Mathematica code is actually on the wikipedia image page that you linked to? $\endgroup$ – Carl Lange Feb 5 at 9:21
5
$\begingroup$

Update: A more streamlined version

Plot[Evaluate@ChebyshevT[Range[0, 4], x], {x, 0, 1},
 PlotStyle -> {Blue, Orange, Green, Magenta, Purple}, 
 Frame -> True, Axes -> False,
 GridLines -> Automatic, GridLinesStyle -> Directive[Gray, Dashed], 
 PlotLegends -> Placed[LineLegend[{"T0", "T1", "T2", "T3", "T4"}], Top]]

enter image description here

Original answer:

Plot[Evaluate[Table[ChebyshevT[n - 1, x], {n, 5}]], {x, 0, 1}, 
 PlotStyle -> {Blue, Orange, Green, Magenta, Purple}, 
 PlotTheme -> "Scientific", 
 PlotLegends -> Placed[LineLegend[{Blue, Orange, Green, Magenta, Purple}, {"T0", "T1", 
     "T2", "T3", "T4"}], Top]]

enter image description here

Also

Legended[Plot[Evaluate[Table[ChebyshevT[n - 1, x], {n, 5}]], {x, 0, 1}, 
  PlotStyle -> {Blue, Orange, Green, Magenta, Purple}, 
  PlotTheme -> "Scientific"], Placed[
  LineLegend[{Blue, Orange, Green, Magenta, Purple}, {"T0", "T1", 
    "T2", "T3", "T4"}, LegendLayout -> {"Row", 1}], Top]]

same picture

$\endgroup$
  • 2
    $\begingroup$ With a few bells: Plot[Evaluate@ Table[Tooltip[ChebyshevT[n, x]], {n, 0, 4}], {x, -1, 1}, PlotTheme -> "Scientific", FrameLabel -> (Style[#, 12, Bold] & /@ {x, ChebyshevT[n, x]}), PlotLegends -> Placed[Table[Subscript[T, n], {n, 0, 5}], Top]] $\endgroup$ – Bob Hanlon Feb 5 at 3:57
-2
$\begingroup$
Plot[
 Evaluate[Table[ChebyshevT[n - 1, x], {n, 5}]], {x, 0, 1}, 
 PlotStyle -> {Blue, Orange, Green, Magenta, Purple}, 
 PlotTheme -> "Scientific", 
 PlotLegends -> Placed[
  LineLegend[{Blue, Orange, Green, Magenta, Purple}, {"T0", "T1", "T2", "T3", "T4"}], 
  Top
  ]
 ]

 Also

Legended[
 Plot[Evaluate[Table[ChebyshevT[n - 1, x], {n, 5}]], {x, 0, 1},  
  PlotStyle -> {Blue, Orange, Green, Magenta, Purple}, 
  PlotTheme -> "Scientific"
  ], 
 Placed[ 
  LineLegend[{Blue, Orange, Green, Magenta, Purple}, {"T0", "T1", "T2", "T3", "T4"}, 
  LegendLayout -> {"Row", 1}], Top
  ]
 ]

same picture

$\endgroup$
  • 1
    $\begingroup$ welcome to mma.se. This is copy/pasted verbatim from the accepted answer above. $\endgroup$ – kglr Feb 5 at 9:26

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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