Message Boards Message Boards

0
|
2368 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

How to get PlotLegends to display values of a variable?

Posted 1 year ago

I've made multiple graphs of my function f[x,t], one for each different value of my variable t. Currently, my graphs are unlabelled. I want to use PlotLegends to label each graph with its corresponding t value. When I try the following code, I just get "t ={t}", just the letter {t}, as the label on all the graphs, and not the t value itself. How can I get PlotLegends to display the value of t corresponding to each graph, and not just the letter t every time? Below is the code Im using,

ClearSystemCache[]

h=1; l=10; v=1;

y=Sum[(8h/(n^2Pi^2))(2Sin[n Pi/4]-Sin[n Pi/2])Sin[n Pi x/l]Cos[n Pi v*t/l],{n,1,40,1}];

y2=Table[Plot[y,{x,0,10}, AxesLabel->{"x","y[x,t]"}, PlotLegends->"t={t}"],{t,0,2l/v,.02l/v}];

ListAnimate[y2]
POSTED BY: Lewis Jones
2 Replies

Lewis, you have to convert the respective value of t into a string first, e.g.:

PlotLegends -> "t=" <> ToString[t]

EDIT: Just as an aside - ClearSystemCache[] does not clear old definitions, etc.. I guess you rather want

ClearAll["Global`*"]

or Clear[] or Remove[]

POSTED BY: Henrik Schachner

If you are using notebook specific contexts (I do to avoid polluting the Global namespace) then

ClearAll[Evaluate[Context[] <> "*"]]
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract